How to Rename Git Local and Remote Branches
Table of Contents
Sometimes, you will need to rename a local or remote branch in Git, for one reason or another.
In this post, we're going to learn how you can rename a local or remote branch in Git.
Renaming local branches
Renaming a local branch is easy. Simply use the git branch
command and pass it the -m
flag.
BASHgit branch -m <old-branch-name> <new-branch-name>
This will rename the local branch <old-branch-name>
to <new-branch-name>
locally.
Now delete the old branch remotely:
BASHgit push origin --delete <old-branch-name>
Pushing new branch to remote
Now that you've deleted the old branch from the remote, you can push your newly-renamed branch to remote.
This is how you can push a new branch to remote:
BASHgit push origin <new-branch-name>
Now, simply reset the upstream branch to the new remote branch:
BASHgit push origin -u <new-branch-name>
That's it, you should have successfully renamed your branch locally, then reflected the updates on remote.
Conclusion
In this post, we learned how to rename your branch locally, then push these changes to remote.
Hopefully, you've found this useful.
Happy coding!
- Getting Started with Svelte
- Create an RSS Reader in Node
- Git Tutorial: Learn how to use Version Control
- How to Serve Static Files with Nginx and Docker
- Best Visual Studio Code Extensions for 2022
- How to deploy a PHP app using Docker
- Getting Started with Sass
- Learn how to use v-model with a custom Vue component
- Learn how to build a Slack Bot using Node.js
- Getting Started with Vuex: Managing State in Vue
- Setting Up a Local Web Server using Node.js
- Using Axios to Pull Data from a REST API