How to Rename a Git Branch

0 min read 80 words

If you want to rename a git branch, then you have a few options, dependent on the use-case.

Option 1 – Rename a Git Branch

git branch -a <oldname> <newname>

Option 2 – Rename the Current Branch

git branch -m <newname>

Option 3 – On Windows

Windows required a capital “-M” instead.

git branch -M <newname>

Push the Local Branch and Reset the Upstream Branch

git push origin -u <newname>

Delete the Old Remote Branch

git push origin --delete <oldname>
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags

Recent Posts