Signup/Sign In

Replace your 'master' Branch with 'main' in Github

Posted in Tricks   LAST UPDATED: NOVEMBER 1, 2021

    Showing solidarity with the ongoing protests around the world fighting for equality for Black communities around the world, Github recently decided to drop the name master for its main branch and name it just main.

    The words "master" and "slave" are used on multiple different occasions in the software development world, be it the master-slave architecture for cluster applications, or the master branch in git repositories, etc. and activists around the world have been protesting against the usage of these terms in the software industry.

    Github master branch is now main

    The CEO of Github confirmed that they are working on making the transition of naming the master branch as main and the work is in progress.

    It's a great idea and we are already working on this! cc @billygriffin22

    — Nat Friedman (@natfriedman) June 12, 2020

    Well, the change is not yet done and still, if you will create a new repository on Github, it will still have the master branch as the default branch. But you can replace your master branch with main branch on Github by creating a new main branch, copying the commits of the master branch to it, and then making the new main branch as the default branch.

    It will hardly take a few minutes to do this change.

    Replace Master with the Main branch

    We will be creating a new branch with the complete commit history of the master branch.

    Run the following command while you are in the master branch:

    git branch -m master main
    git push -u origin main


    Total 0 (delta 0), reused 0 (delta 0)
    remote:
    remote: Create a pull request for 'main' on GitHub by visiting:
    remote: https://github.com/thisisabhishek/github-tutorial/pull/new/main
    remote:
    To https://github.com/thisisabhishek/github-tutorial.git
    * [new branch] main -> main
    Branch main set up to track remote branch main from origin.

    Then open your Github repository in the browser and go to Settings > Branches,

    Then choose the branch main from the default branch dropdown.

    replace master branch with main github

    Then click on Update button next to the branch dropdown.

    replace master branch with main branch github

    Then you will see a pop up to confirm this change of the default branch.

    replace master branch with main branch github

    And we are done.

    Conclusion:

    Now you have the main branch as the default branch. It will require some time for developers in your team to get used to this change as we have a habit of running commands on the master branch.

    Developers around the world have mixed feelings for this change because this change will require some time to sink in. In my opinion, I am personally OK with this change and this is a good gesture and although gestures do not bring any change in the society, they definitely pass on a message.

    You may also like:

    About the author:
    I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight
    Tags:GITGithubHowTo
    IF YOU LIKE IT, THEN SHARE IT
     

    RELATED POSTS