![rename git branch rename git branch](https://phoenixnap.com/kb/wp-content/uploads/2021/04/delete-old-branch-rename-git.png)
Although you can’t rename remote Git branches directly, you can use the commands above to rename a local one and push it to the remote repository. Final Thoughtsįailing to follow naming conventions in Git can lead to various problems, but as you can see, it’s definitely not the end of the world if you’ve made a mistake. Once you’ve performed the sequence of commands listed above, both the local and remote branches in Git will be renamed and you’ll be all good to go. This can be achieved by typing in: git push origin -u Last but not least, you’ll need to push the newly named local branch to the remote repository. If the branch has already been pushed to the remote repository you need to delete it by using the following command: git push origin -delete If you’re on a different branch and don’t want to switch to the local one for some reason, you can use the command below instead: git branch -m old-name new-name Next, you’ll want to rename the local Git branch by using the command: git branch -m This can be achieved by typing in the following command into the terminal: git checkout Your first order of business is to switch to the local branch that needs to be renamed if you haven’t done so already.
#RENAME GIT BRANCH HOW TO#
How to Rename a Local and Remote Branch in Git All you need to fix the problem are a few simple commands, which we’re going to discuss down below. However, there’s no need to worry if you messed up because Git allows users to rename branches even after they’ve been pushed to the remote repository. Since you’re reading this article, chances are that’s already happened to you and you’re well aware of the consequences. To switch to a branch, run git switch branch-name or git checkout branch-name. Needless to say, this is a situation you’ll want to avoid.Įven veterans can sometimes incorrectly name a Git branch and push it to the remote repository before realizing the mistake. git branch -m old-name new-name Step-2: Pushing changes to the remote if the renamed branch is not pushed to the remote then you can push it normally by git push origin new-name if the renamed. Aside from potentially setting back your co-workers, you’ll likely receive more than a few complaints about failing to correctly name your branches. Ignoring proper naming conventions can lead to a number of issues, not just for yourself, but also for everybody else that’s involved. We welcome the use of main as a more inclusive default branch name and are happy to see that our peers at GitHub and Atlassian also support this change. You can also rename a local branch from another branch by using the following two commands: git checkout master git branch -m old-name new-name. Correctly naming your Git branches is always important, especially when you’re working alongside other people on a project. You can learn more about the change in the default branch rename epic.