How to Rename Branch in Git?

Renaming branches in Git is important for keeping your repository organized and understandable, especially when collaborating with others. Clear and descriptive branch names improve project management and help team members identify the purpose of each branch. Renaming branches also ensures consistency and clarity throughout the development process.

Table of Content

  • Approach 1: Using the ‘git branch -m’ command.
  • Approach 2: Using ‘git checkout’ command

Approach 1: Using the ‘git branch -m’ command.

Step 1: Open your terminal or command prompt.

VS code terminal

Step 2: Navigate to the repository directory using the `cd` command.

cd <-directory->

Step 3: Initialize git, add commit, add files and create branch.

git init
git add -all
git commit -m 'first commit'
git branch -m <brach_name>
git branch

Step 4: Now run the following command to rename branch.

git branch -m <-old_branch_name-> <-new_branch_name->

and verify it using git branch

Approach 2: Using ‘git checkout’ command

Step 1: Open your terminal or command prompt.

Step 2: Navigate to the repository directory using the `cd` command.

cd <-directory->

Step 3: Initialize git, add commit, add files and create branch.

git init
git add -all
git commit -m 'first commit'
git branch -m <brach_name>
git branch

Step 4: Run `git checkout “<-old_branch_name->”` followed by `git branch -m “<-new_branch_name->”.

git checkout "<-old_branch_name->"
git branch -m "<-new_branch_name->


Contact Us