Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local and remote branch name is same still getting "The upstream branch of your current branch does not match the name of your current branch "

Tags:

git

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.

like image 216
BigDataLearner Avatar asked Dec 02 '14 19:12

BigDataLearner


People also ask

How do I checkout a remote branch with a different name?

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 .

What is the difference between local and remote branches?

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 does it mean for a branch to be upstream?

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.


2 Answers

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.

like image 117
Justin Howard Avatar answered Sep 23 '22 09:09

Justin Howard


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
like image 21
Ry- Avatar answered Sep 24 '22 09:09

Ry-