Git Rename Branch

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.

Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.