How to Rename a Local Git Branch

February 1, 2023 / How-to Guide

In this guide, we have explained how to rename a local Git branch. Git branches are discrete development paths for your project. They give you a means to work concurrently with your master branch, keeping it free of clutter and unfinished code.

Follow these steps:

  1. Select the branch you wish to rename and execute the command given below. The name of the appropriate branch should be replaced with “old name.”
    git checkout old-name
  2. To find all of your local branches, run the below command:
    git branch –list
  3. Once the branch is selected you can rename the Git branch.
    Now, let us follow the steps to rename:

    1. Using the Git branch command, modify your line by adding the -m option:
      git branch -m new-name
    2. To rename the local Git branch, run the below command:
      git checkout master
      git branch -m old-name new-name
  4. Run this command last to make sure the renaming was successful and to show all local and remote Git branches:
    git branch –a

This was the easiest way to rename the local Git branch.

Hope you grasped everything very well. But, still, if you find any difficulty in executing the process, you can get in touch with our support team.

Also Read: How to Rename a Remote Git Branch


Spread the love