To rename a git branch, for example when one branch is too far behind and you quickly add a new one, you can rename your branch locally, remove it on remote and then upload the renamed branch as a new one. You can do that using this code
git branch -m old_branch new_branch # Rename branch locally git push origin :old_branch # Delete the old branch git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
props lttlrck
The command with --
git checkout k8 --
may be needed to switch to new branch locally due to error
fatal: 'k8' could be both a local file and a tracking branch. Please use -- (and optionally --no-guess) to disambiguate
This happened when we recreated the same branch and tried to use it locally.