Home > front end >  Git, tracking wrong remote branch after moving commits between branches
Git, tracking wrong remote branch after moving commits between branches

Time:07-11

I needed to move some commits to another, new branch, and I followed the instructions in this answer.
So, as mentioned in the linked question, I went from:

old_branch A - B - C - D - E

to this

new_branch       C - D - E
                /
old_branch A - B 

The problem is that now, if I make changes and try to run "git push" from new_branch, I'm getting the error:

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 . HEAD:old_branch

To push to the branch of the same name on the remote, use

    git push . HEAD

I tried running:

git remote show origin

and I got

* remote origin
  Fetch URL: xxx.git
  Push  URL: xxx.git
  HEAD branch: master
  Remote branches:
    new_branch                         tracked
    old_branch                         tracked
    master                             tracked
  Local branches configured for 'git pull':
    old_branch                         merges with remote old_branch
    master                             merges with remote master
  Local refs configured for 'git push':
    new_branch                         pushes to new_branch (up to date)
    old_branch                         pushes to old_branch (up to date)
    master                             pushes to master     (up to date)

If I try checking:

git status

I got:

On branch new_branch
Your branch and 'old_branch' have diverged,
and have 6 and 3 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

I can push the code to the new_branch by using git gui, but how can I fix this so that I can git push as well?

CodePudding user response:

Set the correct remote tracking branch for your local new_branch branch :

git branch -u origin/new_branch new_branch
  • Related