Have you ever created a Git local branch and realized that you made a typo in its name or forgot to include the ticket number? Fortunately, Git provides an easy way to rename branches using the --move option. In this article, we'll walk you through how to use this option to rename your Git local branches with some practical examples..
Fix Example 1: Renaming the current branch using --move flag
Say you had created a branch with the name - "fix-for-alignmetn" as there is a typo in it you want to change it to "fix-alignment"Git Command Example:
# git branch --move fix-for-alignmetn fix-alignment
As you can see we have made use of the "git branch" command followed by the --move flag and then the old branch name followed by the new branch name.
Fix Example 2: Renaming the current branch using -m flagGit Command Example:
# git branch -m fix-alignment
You can also make use of the shorthand version of the move flag with is -m
Note: If you are renaming the current branch, you do not need to provide the old branch name.
Fix Example 3: Rename a branch that is not current.
Say you are now pointing to the main/master branch and want to rename a different local branch, you can make use of the same syntax as you saw in example 1.
Renaming the branch can help keep your codebase organized and make it easier to track changes.Be cautious while changing the master branch name
Changing the name of a branch like master/main/mainline/default will break the integrations, services, helper utilities and build/release scripts that your repository uses. Before you do this, make sure you consult with your collaborators. Also, make sure you do a thorough search through your repo and update any references to the old branch name in your code and scripts.Read - https://git-scm.com/book/en/v2/Git-Branching-Branch-Management
Facing issues? Have Questions? Post them here! I am happy to answer!
- Fix [oh-my-zsh] Cant update: not a git repository
- [fix] fatal: pathspec index.html did not match any files error
- How to ignore files in git using .gitignore file
- Git Fix: fatal: refusing to merge unrelated histories Error
- Install GitHub Command Line Tool on Mac
- How to change directory in Git bash
- Get List of all local branches git command
- fix fatal: --local can only be used inside a git repository error
- [git] fatal: your current branch 'main' does not have any commits yet
- Git Revision Questions Before the Interview
- Change the default git branch name from master to main
- git command to remove/unstage files from staging area
- Remove git config at Local, Global or System Levels?
- [fix] fatal: this operation must be run in a work tree in git
- Clone a particular remote brach using git clone command
- How do I get a list of all branches in Git?
- How to check your installed version of Git
- Step-by-Step: How to delete a git branch from local as well as remote origin
- Git Commit - Author identity unknown, Please tell me who you are email
- fatal: Unable to create '/c/git_repo/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier.
- How to Rename a Git Local Branch Using the --move Option
- Perform an Empty Commit in Git without anything in Staging Area
- [Fixed] Git Clone email@example.com: Permission denied (publickey) Could not read from remote repository Fatal error
- GitHub: How to Search Code
- Rename git branch on Local and GitHub Remove using Command
- How to Uninstall Android Studio on Mac - Android-Studio
- [Fix] Springboot: Web application could not be started as there was no ServletWebServerFactory bean defined in the context. - Java
- Sign in as different user missing in SharePoint 2013 how to enable - SharePoint
- Java JDBC Batch Update Example with PreparedStatement - Java
- Calculate Volume of Pyramid - C-Program
- Change Google Chrome Browsers default download location - Chrome
- [Solution] IDEA IntelliJ System.out.println function shortcut (sysout alternative for eclipse IDE) - HowTos
- Closest Alternate to Notepad on Mac - MacOS