2

I'm trying to rename a branch of my project, using

git branch -m old_branch_name new_brach_name

to rename the local branch, which works just fine and the local branch is renamed. But after deleting the old branch name from the remote (either on github or in the git shell) and using

git push origin new_branch_name

I get this output

Counting objects: 92, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (60/60), done.
Writing objects: 100% (92/92), 488.48 KiB | 0 bytes/s, done.
Total 92 (delta 3), reused 0 (delta 0)
To https://github.com/<username>/<repo_name>.git
 * [new branch]      new_branch_name -> old_branch_name

And the old branch name still shows on both the remote and on github.

What gives? I've googled and searched here quite a bit and I can find no other instance of someone renaming a branch and having git rename it back when pushing it to the remote.

Young_Maker
  • 293
  • 4
  • 10

2 Answers2

2

Even though you changed the local name of old_branch_name to new_branch_name, this local branch is still tracking the same remote branch on GitHub (or wherever you repository is). In order to tell Git that you want this local branch to track a different remote branch, you need to explicitly tell it that the new local branch also has a new upstream location:

git checkout new_branch_name
git push --set-upstream origin new_branch_name

In the above git push command, new_branch_name is the name of the remote branch which you want your local branch to track.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • This does the same thing. The output is `* [new branch] new_branch -> old_branch Branch new_branch set up to track remote branch old_branch from origin.` – Young_Maker Feb 10 '16 at 19:17
0

Even though you changed the local name of old_branch_name to new_branch_name...

You still need to push the old_branch_name deletion (after having pushed the new name), as seen here:

git push origin :<old_name>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250