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!
- Change the default git branch name from master to main
- [Fixed] Git Clone email@example.com: Permission denied (publickey) Could not read from remote repository Fatal error
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- [fix] zsh: command not found: git
- How to Install Git on Windows
- Setup Git + Visual Studio Code Tutorial
- How to undo last Git Commit on Local Repository?
- Install GitHub Command Line Tool on Mac
- How to Create a Git Branch in 6 Different ways
- Fix Git: Warning: could not find UI helper GitHub.UI on Windows
- Git Config Command - A Deep Dive
- Step-by-Step: How to delete a git branch from local as well as remote origin
- How to Add Git Bash Option to Windows Terminal List
- Command to Clone Repository Using Git Bash
- How to remove or unstage a file from git staged area
- Get the file location of git config values
- GitHub: How to Search Code
- How to check your installed version of Git
- Fix: error: src refspec master does not match any failed to push some refs to Git
- Git: Step-by-Step - How to Push Local Brach to GitHub
- How to Merge Branch into Master Branch
- fix fatal: --local can only be used inside a git repository error
- Fix: Git Pull Error: unable to resolve reference refs/remotes/origin/master: reference broken
- Change the default diff or commit editor for git
- Git Fix: fatal: refusing to merge unrelated histories Error
- How to Show Full Website Address on Safari for Mac (Ventura/Sonoma) - MacOS
- How to set background color in HTML page? - Html
- Launch Notepad++ html document in any web browser - NotepadPlusPlus
- Create SharePoint Site Collection with new Content database in existing web application - SharePoint
- Run Java Code Every Second - Java
- hibernate.cfg.xml Configuration and Mapping xml Example - Java
- MySQL : Error :1004 SQLSTATE: HY000 (ER_CANT_CREATE_FILE) Can't create file - MySQL
- How to install homebrew (brew) on M1 Mac - MacOS