How to Rename a Branch Locally and on GitHub: 1-Min Guide

Renaming a branch might seem like a small task, but it can have a big impact, especially if you're managing a project with multiple collaborators.

Whether you're cleaning up branch names or fixing an accidental misnaming, this step-by-step guide will walk you through renaming a branch locally and on GitHub, with a demo to make it straightforward.

How to Rename a Branch Locally and on GitHub

Steps to follow:

1. Run the command 'git branch -m' followed by <old branch name> and <new branch name>.

Ex- 'git branch -m feat/input fix/input'.

2. The branch name has been successfully updated.

3. Push the renamed branch to GitHub using 'git push origin <new-branch-name>'.

4. The renamed branch has been successfully pushed to GitHub.

5. Delete the old branch from GitHub using the command

'git push origin --delete <old-branch-name>'.

6. The old branch has been successfully deleted from GitHub.

That's it! This is how you rename a branch both locally and on GitHub.

Conclusion

Renaming a branch locally and on GitHub is simple and helps keep your repository organized.

Whether you're streamlining workflows or aligning branch names with new goals, these steps ensure everything stays in sync.

Still have questions?

Send an email to archana@leadwalnut.com, OR

Book a FREE consultation with an expert developer here.