Today I learned how to rename a git branch from the CLI.

Rename a git branch

How to rename a local git branch

To rename a local git branch, you can use the command git branch with the option -m.

If you're in the branch you want to rename, just do

git branch -m new-name

If you are in another branch, you can do

git branch -m old-name new-name

How to rename a remote git branch

If you want to rename a remote git branch, you can just delete the old branch and push the new one.

I also found the command

git push origin :old-name new-name

but I have never used this command and when I quickly scanned the documentation for git push I couldn't find out what the :old-name new-name really does. (Comment below if you know!)

That's it for now! Stay tuned and I'll see you around!

Become a better Python 🐍 developer πŸš€

+35 chapters. +400 pages. Hundreds of examples. Over 30,000 readers!

My book β€œPydon'ts” teaches you how to write elegant, expressive, and Pythonic code, to help you become a better developer. >>> Download it here πŸπŸš€.

Previous Post Next Post

Blog Comments powered by Disqus.