When I do git branch I get that I am on branch v0.2.
git branch
v0.1
* v0.2
But when I do git push it says "The upstream branch of your current branch does not match the name of your current branch "
git push
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:v1.1
To push to the branch of the same name on the remote, use
git push origin v0.2
Initially I had named this branch v1.1 but now I have renamed it to v0.2 locally and remotely.
How can I fix this once and for all.
To be precise, renaming a remote branch is not direct – you have to delete the old remote branch name and then push a new branch name to the repo. Step 2: Reset the upstream branch to the name of your new local branch by running git push origin -u new-branch-name .
The local branch exists on the local machine and can be seen only by the local user. The remote branch is a branch on a remote location. Sometimes, you want to know what files are changed between the local and remote repositories.
What is Git Upstream Branch? When you want to checkout a branch in git from a remote repository such as GitHub or Bitbucket, the “Upstream Branch” is the remote branch hosted on Github or Bitbucket. It's the branch you fetch/pull from whenever you issue a plain git fetch/git pull basically without arguments.
Git keeps track of which local branch goes with which remote branch. When you renamed the remote branch, git lost track of which remote goes with your local v0.2
branch. You can fix this using the --set-upstream-to
or -u
flag for the branch command.
git checkout v0.2
git branch -u origin/v0.2
Now when you do git push
, git will know which branch your local v0.2
is paired with.
You may have renamed the branch both locally and remotely, but the local branch’s upstream appears to still point to the old name. You can verify this by doing a
$ git branch -vv
…
* v0.2 01234abc [origin/v1.1]: Some message
… where, if it indeed says origin/v1.1
in square brackets, your upstream needs to be changed. It should be as easy as specifying the -u
flag when pushing, though:
git push -u origin v0.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With