How to Rename Git Local and Remote Branches
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
git branch -m <old-branch-name> <new-branch-name>
This will rename the local branch
Now delete the old branch remotely:
git 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:
git push origin <new-branch-name>
Now, simply reset the upstream branch to the new remote branch:
git push origin -u <new-branch-name>
That's it, you should have successfully renamed your branch locally, then reflected the updates on remote.
In this post, we learned how to rename your branch locally, then push these changes to remote.
Hopefully, you've found this useful.
- Managing PHP Dependencies with Composer
- Getting Started with Express
- How to Set Up Cron Jobs in Linux
- How to deploy a .NET app using Docker
- How to deploy a PHP app using Docker
- Getting Started with Deno
- How to deploy a MySQL Server using Docker
- How to Scrape the Web using Node.js and Puppeteer
- Build a Real-Time Chat App with Node, Express, and Socket.io
- Using Push.js to Display Web Browser Notifications
- Getting Started with React
- Setting Up Stylus CSS Preprocessor