Git rename branch

Share on:

The following blog post covers how to rename the default branch in GitHub. If you have wondered how to do this task it is basically two discrete steps.

    1. Rename the default branch
    1. Update the local clone

Once complete the branch will be available and response as the default.

Rename Default branch

The default branch configuration can be changed from the GitHub interface. From the GitHub interface select the repo to update

  1. Go to the repo setting option
  2. Select the Branches option
  3. Rename the Default branch to whatever you like

Local Clone

With the default branch renamed the local clone also needs to be updated. In the below example the default MASTER branch is being renamed to MAIN.

GitHub recommend the following to update the local clone:

1git branch -m master main
2git fetch origin
3git branch -u origin/main main
4git remote set-head origin -a

Alternatively delete the local repo and repull a local clone.