Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Renaming GitHub Master Branch to Main Branch?

Introduction

GitHub is one of the most useful tools in a developer’s arsenal today, with several organizations using Git to control and deploy code. Recently, Github has implemented the Conservancy’s suggestion and has stopped using the term master when a new repository is initialized. Now, the master Branch is called the main branch, and GitHub stated that they are encouraging projects to switch to branch names that are meaningful and inclusive while making it easier for them to use the new default name. This was carried out after the 2020 protests when the term master was found to be offensive to people.

If you’re looking to change the name of your GitHub branch as well, then this blog will help you accomplish just that in a few simple steps:

Guide to rename branch

Note: People with write permissions to a repository can rename a branch in the repository. People with admin permissions can rename the Default Branch.

1. First clone repository to your local.

git clone repo_url

2. Checkout branch which you want to rename. For example, “master” to be renamed to “main”.

git checkout master

3. Move your “branch_name_to_be_renamed” to “new_branch_name” –

git branch -m master main

4. Push your new branch name to GitHub repo

git push -u origin main

(Here -u sets the new branch as the local default at the same time)

git remote set-head origin main

(This line ensures our local HEAD points to our new branch on GitHub)

5. Verify branches and you can find origin/HEAD -> origin/main

git branch -r

6. Go to GitHub and change your default branch to the newly created branch. If it is not the master or default branch skip this step. To achieve this, go to your repository settings > Branches and select the default branch.

7. Delete old branch. Before taking this step go to  your repository on GitHub and verify your new branch appears in the list.

git push origin –delete master

8. In this step you should have to verify your code, scripts, automation, integrations for references to the master branch. For example, check files like: travis.yml, .github/workflows/, .circleci/config.yml, etc. and make sure there are no external services or links relying or referencing the master branch.

9. Git does not override some native commands like git init, soyou can create git new using following command:

git config –global alias.new ‘!git init && git symbolic-ref HEAD refs/heads/main’

Tip: While you are renaming other branches than set your origin to the default branch. This can be achieved using step 8, just change the default branch name.

What team must follow

Within team if they have local clone of repository, they must perform following steps:

  1. Checkout master branch: git checkout master
  2. Rename it too main: git branch -m master main
  3. Get latest commits: git fetch
  4. Remove existing tracking connections: git branch –unset-upstream
  5. Create new tracking connections: git branch -u origin/main

Things to Keep in Mind

Renaming a branch is not terrifying or complex.

You should always backup your repository for recovery.

Wrapping Up

This guide explained how to successfully rename your branch to a more creative and inclusive name as per GitHub and the Conservancy’s advice. By following all the steps mentioned above, you should be able to accomplish this without any trouble. However, if you have any queries about GitHub or related topics, feel free to get in touch with our DEV IT engineers for the info.

You May Also Like

  • Remove Unwanted Files and Folders from GitHub Repository

The post How to Renaming GitHub Master Branch to Main Branch? appeared first on DEV IT Journal.



This post first appeared on DEV IT Journal - Simplifying IT, Empowering Busine, please read the originial post: here

Share the post

How to Renaming GitHub Master Branch to Main Branch?

×

Subscribe to Dev It Journal - Simplifying It, Empowering Busine

Get updates delivered right to your inbox!

Thank you for your subscription

×