My colleague and I have been trying to put together a clear, consistent procedure for renaming a git branch locally and remotely.
Assuming we have a branch oldname
both locally and on remote, and want to rename it to newname
, and we have checked out locally branch oldname
, following https://stackoverflow.com/a/30590238/1592322 (and other similar suggestions across the internet), these steps work for my colleague:
git branch -m newname
git push --set-upstream origin newname
Whereas I have to follow an intermediate step of explicitly unsetting the upstream information (as suggested by user:22992 in that same stack overflow link I provided above):
git branch -m newname
git branch --unset-upstream
git push --set-upstream origin newname
If my colleague uses my (slightly longer) procedure, then that second additional step git branch --unset-upstream
results in an error:
Fatal: The current branch newname has no upstream branch.
So we can't use the same consistent procedure, and guess we just have to watch out for this in general. It seems to me that the behavior of git branch -m
differs between different git versions. Is this correct? Why is there a difference in behavior?
My colleague is running git version version 2.18.0.windows.1 . Whereas I am running 2.17.2 (Apple Git-113) on a macOS 10.13.6.
master 7dcd2fe [origin/master] added test file * newname 7dcd2fe [origin/oldname] added test file
and looking at remote via the GitHub web interface lists only `oldname` (and `master`) as branches. – H3007 Jul 09 '20 at 21:29