Changing local Git clone from master to main

I never understood why Git chose master as the default branch name, MAIN in CVS seemed more sensible, but perhaps Torvald’s animosity towards CVS and SVN plays a role. Presumably trunk in SVN is a reference to the tree-like structure, of a repository, but I still find it an odd choice.

Either way Mercurial’s default seems sensible1 as well as CVS’ MAIN and ultimately that means the new default branch name main in Git is a perfectly adequate choice in my book.

There are two ways to go about this. Say you have a clone of some third-party code and the upstream repo changed their default branch name from master to main, so subsequent git pull attempts fail due to the non-existent master branch on the still-configured remote. This is scenario one. And it’s easy to deal with.

  1. Rename local master to main
    git branch -m master main
  2. Set up our new main branch to track origin/main
    git branch --set-upstream-to=origin/main main
  3. Have HEAD point to the tip of origin/MAIN
    git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

At this point you should be able again to git pull.

Another scenario is when you own the remote on some Git hosting platform and you want to switch the default branch name from master to main. This will be our scenario two.

  1. Rename local master to main
    git branch -m master main
  2. While on this (new) main branch (e.g. via git switch main), push your main and set origin/main as the new upstream in one command
    git push --set-upstream origin main
    (--set-upstream can be abbreviated -u)
  3. Have HEAD point to the tip of origin/MAIN
    git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
  4. Delete the master branch on the remote
    git push origin --delete master

I believe there was a way to do this in a fully remote fashion, too (without the git push -u), but I can’t remember the details right now. Perhaps I’ll amend this post later.

That’s it folks.

// Oliver

NB: I really despise the underlying woke ideology that prompted the name change, claiming that “master” has an inherent connotation with slavery of African-Americans. Oh well, of course the USA is the center of the multiverse … what else?! 🤨 … Certainly the English word “master” has been used in this context much like the vast majority of all humans that ever roamed the Earth lived in serfdom to some “lord” or “master” until relatively recently2. And “lord” is even still considered an honorary title in some countries to this very day3. But the noun “master” also has a verb “to master (a skill)” tied to it. Also the “gold master” when producing a CD or DVD or the “mastering process” in the same context hardly can be said to have any connection to US-American slavery. And the strawman argument that the terminology has been appropriated this way in IT as can be witnessed with “bus master” and “bus slaves” has absolutely no connection to Git. I never heard anyone talk about “slave branches”. What will be next? This is just ridiculous and reveals a mindset that makes kindergarten children seem like wise old people …

  1. … although it should be mentioned that branches in Mercurial are conceptually a superset of the local branches in Git; Mercurial calls a concept similar to Git’s branches: bookmarks. []
  2. And probably not much longer, looking at recent developments. []
  3. I don’t know with which justification. Being an atheist I have a hard time accepting a “nobility” who ultimately claims their power and entitlements were bestowed onto them by some deity. []
This entry was posted in EN, Software, VCS and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.