Getting error when pushing code to git branch

969 Views Asked by At

I'm trying to push code to my branch and I haven't made any commits to the branch previously. git add and git commit work fine but when I do git push, I get the following error:

fatal: The current branch my_branch has no upstream branch. To push the current branch and set the remote as upstream, use

git push --set-upstream origin my_branch

When I run the suggested command, I get another error:

fatal: my_branch cannot be resolved to branch

I tried git pull too and that works fine but when I do git pull specifically for my branch like, I get another error:

git pull origin my_branch

fatal: couldn't find remote ref my_branch

Thanks in advance:)

1

There are 1 best solutions below

0
On

Thanks to everyone who helped but I was able to fix the issue by doing this:

  1. created a new branch
  2. git branch -u origin/master (this is to set a remote branch for my branch)
  3. committed changes on the new branch

//git indicated that my branch and master branch have diverged so I did step 4

  1. git pull
  2. Resolved conflicts
  3. git push origin HEAD (used HEAD to push to the remote version of my branch)

I found this link helpful: https://intellipaat.com/community/21465/git-status-on-branch-master-nothing-to-commit-working-tree-clean-however-with-changes-commited

Also, creating a new branch may not be necessary, as long as other steps are the same.