How to rename a branch in Git

If you haven’t pushed your local branch to a remote branch in Git and you would like to rename your current local branch, you should proceed as follows :

Run the command:

git branch -m <newbranchname>                                [git rename current branch command]

Where -m refers to “move” operation.

Read: How to Delete a Git Branch Locally and Remotely

If you are on a a case-insensitive file system like Windows, you would need to use -M as follows:

git branch -M <newname>

 

Answer due to Siride


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Nikolaus Oosterhof

Nikolaus holds a degree in software development and has a strong passion for all things tech-related, especially gadgets with screens. Though he is nostalgic for older phone models, he's a retired gamer and continues to enjoy programming in open-source environments. Additionally, Nikolaus enjoys writing about Linux, macOS and Windows and has experience designing web pages.

Leave a Reply