Scott Hanselman

Easily rename your Git default branch from master to main

June 08, 2020 Comment on this post [38] Posted in Open Source
Sponsored By

The Internet Engineering Task Force (IETF) points out that "Master-slave is an oppressive metaphor that will and should never become fully detached from history" as well as "In addition to being inappropriate and arcane, the master-slave metaphor is both technically and historically inaccurate." There's lots of more accurate options depending on context and it costs me nothing to change my vocabulary, especially if it is one less little speed bump to getting a new person excited about tech.

You might say, "I'm all for not using master in master-slave technical relationships, but this is clearly an instance of master-copy, not master-slave."

UPDATE: There is Good analysis of the whole main branch convo in the Git Rev News: Edition 65. Git likely uses master in the context of "master copy" or "master recording."

So we see that while the word master doesn't always connote slave, for many, it's evocative via basic word-association and they just don't want to look at the word on their prompt all day. Choice is cool.

I have had dozens of git repositories that have 'master' as the main branch. Changing that would be a hassle right?

image

Let's see. I'll just "git branch -m master main" and then push it back! Remember that -m is --move so your history isn't changed! Even better I can "git push -u origin main" to set the upstream at the same time.

D:\github\WindowsTerminalHere [master]
> git branch -m master main
D:\github\WindowsTerminalHere [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/shanselman/WindowsTerminalHere/pull/new/main
remote:
To https://github.com/shanselman/WindowsTerminalHere.git
* [new branch] HEAD -> main

That was easy.

NOTE: Changing the default branch to "main" also has the benefit of starting with "ma" so that autocomplete <TAB> muscle memory still works. Another great option for your main github branch is "latest." The goal is to just be unambiguous.

Now I just need to change my default branch in my GitHub settings for my repository.

image

I can also update the tracking branch manually as seen here, but if you use git push -u origin main it'll do both.

git branch -u origin/main main

The last thing to think about is if you have a CI/CD, GitHub Action, Azure DevOps pipeline or some other build system that pulls a specific branch. You'll just change that to main. However, usually unless your CI explicitly calls for a branch by name, changing master to main will "just work!"

NOTE: For more complex repos also check your protected branch rules.

image

This is because -m is --move and all your reflog is unchanged!

TL;DR in conclusion:

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

Updating local clones

If someone has a local clone, then can update their locals like this:

$ git checkout master
$ git branch -m master main
$ git fetch
$ git branch --unset-upstream
$ git branch -u origin/main
$ git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

From the tweet above (Thanks Brad from XUnit.net!), these steps

  1. Go to the master branch
  2. Rename master to main locally
  3. Get the latest commits from the server
  4. Remove the link to origin/master
  5. Add a link to origin/main
  6. Update the default branch to be origin/main

You can add an alias "git new" that will default to whatever starting branch you like. (NOTE: This is no longer needed, set below)

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

UPDATE! As of Git 2.28 you don't need an alias as above, as there is a new config option called init.DefaultBranch. Just set it and forget it.

git config --global init.defaultBranch main

Hope this helps! Other good names are latest, trunk, and stable!


Sponsor: Have you tried developing in Rider yet? This fast and feature-rich cross-platform IDE improves your code for .NET, ASP.NET, .NET Core, Xamarin, and Unity applications on Windows, Mac, and Linux.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
June 08, 2020 8:21
Thank you, Scott! I unfortunately had never considered this. Is there also a way to set this as the default branch name on
git init
?
June 08, 2020 9:54
Can I delete the master branch afterwards also? Does GitHub allow this?
June 08, 2020 10:06
Thank you!

I don’t know the stack, but I really hope someone makes a PR to the git repo for renaming. I propose the command:
> git blm main

And a new default for git init too.

With love and solidarity ✊🏿
June 08, 2020 10:45
Just learned something new, but I won't change master branch name in my projects.
June 08, 2020 11:15
Matthias, yes you can
git push origin --delete master
if you want
June 08, 2020 11:28
But in git concept master has to be understood as the 'original', the 'master copy'. There is no association with master and slaves. There is no git slave concept.
That makes no sense.
In some projects the initial branch is not the main branch. But it will always be the first ever branch, the original branch.
I think to show black people our respect and solidarity we do not have to rename everything that is called master or black as long as there is no association with master & slave or black as something bad.
If we rename all the things this tends to have the opposite effect, if we always associate master with slavery and when the word "black" in our minds is something bad that we have to rename directly.
Rob
June 08, 2020 11:44
Please correct me if I understand wrong, but for git the term "master" is not the same context as the opposite of "slave" is it? My understanding was that master means "primary" or "principal", but has other meanings like "expert", "overcome" or of course "slave owner".

June 08, 2020 11:52
It's true that, in the context of git, `master` is not used as part of a `master/slave` relationship. `Master` has many meanings that are not connected to slavery - just as `black` has many meanings that aren't related to race.

But it's far from the only appropriate word for the concept represented by the `master` branch. Why _not_ adopt terminology that doesn't have the overloaded concepts?
June 08, 2020 13:02
sorry guys, I know you have good intentions here, but I believe you are actually doing damage.
I noticed a trend recently that in many cases, our black fellows don't take a situation offensive - the white liberals do it in their name - at least that is what they think they do. For sure, that have not been asked to do so. So they just assume they are acting in other persons best interest.

But it actually does something opposite to the intention. It implies that black people are incredible fragile. It implies that you cannot be relaxed in their presence, but must constantly pay attention to your vocabulary.

I mean, think about it. Is this really closing the racial divide or expanding it? Does anyone particularly enjoy standing in the middle of mine field? Because this is what you are effectively doing. You are tossing mines around race, so I am no longer able to enjoy the company, but constantly fear that something is about to explode.
June 08, 2020 13:49
I never thought the `master` branch naming was particularly good, I guess it suppose to mean the "master copy", but there are way better names to choose from. E.g. Mercurial used the name `default`, SVN used `trunk`.

Aside from being the default branch name when you create a new git repository, the master branch is not special in any way, it doesn't have any meaning for git itself, so deleting or renaming it doesn't hurt at all.
June 08, 2020 14:23
I fully agree that the "master/slave" terminology is inappropriate, and we should strive to change to promote inclusivity. Some other words and phrases are also problematic because of their history. I do not believe that we need to find and remove all instances of the word "master" because of particular cases that are problematic.

In the context of git, the word "master" is not used in the same way as "master/slave". I have never heard the other branches referred to as "slaves" or anything similar. I will admit that I've never seen the etymology of the phrase "master" or "master branch" in the context of git, and a few searches don't reveal anything canonical. I've always taken it in the same sense as "master recording" (the source for deployments) or "master copy" (the origin for all other copies and derivatives).

Before anyone does this, they should consider the cost of change. On existing projects, consider the global effort to change from origin/master to origin/main. On both new and existing projects, the cost of being different than git convention and nearly every book, tutorial, and blog post. Is the cost of change and being different worth it for a phase that, in its context, is not a problematic phrase? Is this a way to make your organization, team, or project more inclusive and more accessible for others to join?

If you are for this, how do you feel about the IEEE's Professional Software Engineering Master certificate? Or Scrum's Scrum Master role? Or, if you look beyond software, people who are masters of ceremonies or chess masters? Or the mastery of a skill? If you support an effort to eliminate the word master.

Of course, I could be wrong. However, I have yet to hear from someone who claims that "master" in the context of git branching, is an example of exclusive language. People who are not excluded should not assume that changes we believe would be helpful are truly helpful or in the best interests of others. Instead, we should focus our efforts on changes that promote inclusivity, respect, and safety.
June 08, 2020 15:21
Dear Scott,
I’ve always been fan of your work and follow you for more than a decade now, but this time I couldn’t disagree more.

I’m sorry but I won’t be renaming things at will driven by huge misconceptions imposed by a raising irrational political correctness. You see, languages are tricky! Even though words can have meaning by itself, you can only extract a real meaning when put in context.

You can’t say that words hurt by themselves! At least not the ones that can be applied to such broad spectrum like the “master” on this case you’re. Like others said, in the context of git there is no slavery association. When you try to reduce a single word that has broader meaning like that to the context of a shameful thing like slavery you lose it all.

Masters are very important things of life. They are people who have improved themselves on different aspects of life and are devoted to enlighten other people life’s on the matters that they’re skillful. And as the git usage present it doesn’t even exclusive to person. Things can be important masters in the life of persons, like books, pictures, poems. This is the golden meaning of the master word, and trying to reduce it to a distorted concept of masters like we have in a master slavery relationship makes you lose all the rich good meaning of this word.

The same goes on with several words and sentences targeted by this political correctness thing. I’m sorry, but trying to eliminate every little piece that can cause pain to the life of some groups of people won’t make the problems go away, neither will really bring any consciousness to the issues it “may” carry (may here is very important verb, because as I said before, words have several meanings and they always must be put in context before being criticized by themselves).

I would kindly invite you to rethink on your post and rewrite it, not trying to convince people that they should avoid using the “master” word, that carry on itself so deep and beautiful meaning, but instead trying to explain this good meaning and enlighten people about the bad meaning to which sometimes this word is carried on specific contexts.

That said, I’ll keep up with “master” branches on my repo, because it will keep representing to me the stable and deeply thought pieces of software that must be carried on as the “masterpieces“ of that work. “Main” doesn’t really carry this meaning, being an opaque label.

My best regards.
June 08, 2020 17:07
I believe there is a thoughtful debate worth having here. I myself go back and forth on whether this issue is trivial, or is indeed contributing to the lack of diversity in technology. One only has to look at Facebook, where a nearly all white executive team decided that Donald Trump's posts do not violate community standards, to see the detrimental effects caused by a lack of representation. The question worth asking is this: Do these issues (like have having 'master' as the primary branch) create an exclusionary environment where non-white technologists feel unwelcome? I can't help but notice that most of those commenting in this post are white and male (as am I), so it would be helpful to have someone with a different background add their opinion on this...
June 08, 2020 17:32
Dear Scott,

According to your advise we have renamed branch to main in all our applications. We admire your intention to make our world free of discriminations.

Best wishes, Sergey
https://lgbtnet.org/en
June 08, 2020 18:18
I'll probably get roasted for this but I have a sincere question. I understand the master/slave context and why that's wrong. Can the word master be used at all anymore or is it off limits?

If someone is a "master craftsman" should we not say that (being defined as someone who has the highest proficiency at a skill)? I am asking from a place of wanting to learn and not a place of being purposely obtuse.
June 08, 2020 18:21
Hi Scott,

Although I've been thinking of 'master' as 'master copy', it can also be thought of as 'it owns everything else.' For those that don't like main, perhaps a tree analogy would work since we already do branching. How about 'trunk'? Or 'root'?

We also have used 'master' and 'slave' with hard drives. A better way would be 'primary' and 'secondary', or something else more generic that still defines the relationship as needed.

Thanks
June 08, 2020 18:22
Hi, I'm neither native English speaker, nor USA citizen, but I've a small question: is word `master` has negative context outside of `master-slave` phrase?

In other words, can I name someone a master (to emphasise someones skills) and became an offensive person/racist?

Thank you.
June 08, 2020 19:22
It’s not that it’s racist. It’s that it’s outdated and evokes the master relationship. It’s also that there are a dozen better terms available. It’s also a choice. Choose what works for you.
June 08, 2020 19:41
I don't think master/slave has any bad context outside of master/slave human relationships. Words have context and it is important to look at the words in context because the meaning can be entirely different. There is no reason to get rid of a word from the English language just because in one context it would have a negative context. People need to learn nuance. Not everything is black and white - most things in life are grey.

As for renaming to "main". Well, if you are using Azure everything defaults to "master" and it would make doing CI/CD set up more difficult if you used a different term. We used to use "Dev" and did a lot of work changing over to "master" just to make the DevOps job easier.
Jon
June 08, 2020 20:29
Due to my habit of skimming articles was confused on why there were so many comments on a blog post about a simple github tip. Then I read the first paragraph, honestly I never connected git master branch being related to master/slave. Always consider the master as the source of truth / pristine copy. Back in my undergrad days learning about computers I was always put off(Didn't help that I was the only Black person in the class) by the master/slave terminology when learning about setting up RAIDs, servers and anything to deal with multiple hard drives. So I can definitely see how one could tie them together since both disciplines fall under the same umbrella. But sitting back and thinking about it, it's weird that it's setup as master and branches. Like they wanted to do master/slave but had second thoughts and just left master. Trunk and branches make way more sense in that regard. With that being said I highly doubt I go retroactively changing the branch name.

Also did not know about the -u shortcut
Guy
June 09, 2020 10:08
I have a problem with updating with the third step, which means that I have trouble receiving commitments from the server. Can you help? thank you
June 09, 2020 11:00
My basic rule in life is that if you aren't intentionally offending or causing harm to someone then do what you like. So on that basis if people want to rename master with main then go for it.

That said, personally I don't see any reason to change the name of something if it wasn't intended to be offensive. If you do then where do you stop? By avoiding words you then make them offensive and need to stop using them everywhere (Should Dr Who drop The Master?). You personally can't now ever use the word master because you've stated it could cause offence, therefore if you now use it you are doing so knowing you could be offending someone, and to willingly say something that could offend someone is in itself offensive.

Lets not forget there are other groups also suffering in the world. Someone suggested using the word tunk rather than master, but given that a trunk is most associated with an elephant and elephants are hunted, is that appropriate?

The other day I was buying a garden water hose connector and it turns out the bits are called male and female. Presumably because one has an outy bit and the other an inny, but in a transgender world I can see how that is offensive to some people, so should they be renamed? The term Pansy has also been used to describe a Gay person in the past, so should we rename the flower? Some may say these suggestions are ridiculous but will they be in 15 years time?
Tim
June 09, 2020 12:50
I prefer main or default over master too, also because in the past I had many mercurial repos and some of my git repos are moved from mercurial, moreover I find these terms more neutral and technical sounding.

In any case I have to admit that the point of somecoder is very relevant and spot on. I'm totally for the equality but at this stage we are literally introducing taboo: beware that it is a double sided blade and can cut also the people we are trying to defend.

Also consider that to me (I'm not English mother tongue) "master" is just another conventional word and doesn't carry any racist meaning, to me sounds like "the one in control". Natively English speaker that can grasp these nuance are, probably, a minority over the totally of the humanity.

I think it is better to care more about the content, the attitude and the opportunity, rather than these formalisms.

Anyway, I'm happy that main is the new master, and thanks for collecting all these useful commands in a nice article:)
June 09, 2020 13:34
Interesting post. Unfortunately, I use `git worktree` heavily in my workflow. So for many projects I have a directory called `master` which has the `master` branch, with other branches on worktrees. I can rename `master` to `main` as a branch, but this will make it inconsistent with the directory. If I move the directory, it will break all the worktree directories.
June 09, 2020 13:36
I think this is confused by the fact the word master can be both an adjective and a noun. In the context of git, it's an adjective (it describes the purpose of the branch) and just means primary or principal, unlike with Jenkins where it's used as a noun along with the word slave. In that case, I'd agree, there are better words.
Ant
June 10, 2020 5:07
For those making the “master copy” argument, it turns out that Git’s “master” branch terminology does not appear to come from “master copy” but is a legacy of Bitkeeper’s “master/slave repositories” concept.

You can trace it yourself in the archives: https://mail.gnome.org/archives/desktop-devel-list/2019-May/msg00066.html (I learned this from a tweet https://twitter.com/tobie/status/1270290278029631489?s=21)

Even if it was a “master copy”, I think the name change to avoid overloaded terms is worthwhile. Just wanted to point this out in case it helps some make a decision on what they want to do.
June 10, 2020 8:46
Another version of git new:

git config --global alias.new '!git init && git checkout -b main && git commit --allow-empty -m \"new\"'

https://stackoverflow.com/q/42871542/2040410
June 10, 2020 10:26
Thanks for the tip Scott, I'll give it a spin in private projects and see how it goes.

It's illuminating how a tip for creating accommodating environments for black engineers gets this much push back. It's not like Scott was declaring a manifesto, it's just a tip!

I mean people are actually taking the time to jump on here and proclaim how they will definitely *NOT* be using this practice thank you very much!

I'm West African, I'd be delighted if I started seeing this in new repos and appreciate the thoughtfulness of even considering it.
June 10, 2020 11:22
I always thought that the term master came from "a master copy" like the pressing of a vinyl record. Records were made from the master copy, like branches are made from the master branch. Seemed like an apt analogy.

I don't know where I got the analogy in my head. Just always been my impression this is where it came from.

Does anyone have a URL to read up on the git master terminology and how it came about?



June 10, 2020 12:05
$10 that everyone in here crying about changing the name of a git branch is also the type to call other people 'triggered'
J
June 10, 2020 13:50
May I also suggest that Microsoft starts calling their whiteboards on the office walls "rainbowboards" since this way it looks like they're to be used only by the oppressors?

What about a black coffee? Am I required to pour in milk on MS premises? But then isn't milking a cow also an example of a master - slave relationship? Plus, if I pour in too much milk, won't the coffee become elitist?

Scott, maybe you remember the event in Prague where you talked about open data and diabetes. You have mentioned some liberal nonsense there about airport security and met only with 500 blunt faces as a response. That is how the US liberal agenda feels to me as well, observing it from Europe.

This industry used to be so much better when people dealt with technical stuff and didn't export the US politics to the world where it just doesn't make any sense.
June 10, 2020 14:24
"There's lots of more accurate options depending on context and it costs me nothing to change my vocabulary, especially if it is one less little speed bump to getting a new person excited about tech."


I think a lot of comments are around the "master" not referring to master-slave relationship are fair enough, but Scott's point here is the one that made me decide its a change worth doing.

Even if there isn't an explicit relationship in this context - it costs me nothing to change, and if someone can deal without the connotations of "master" stirring negative thoughts or emotions in someone else, isn't it worth it?

Of course, I'm not saying things shouldn't just be done because they are 'easy', but even still it is a net-good for people like Scott to help us round the corners and make our industry more inclusive and welcoming to people.
June 10, 2020 19:00
Well, the discouraging thing about this is that it breaks Github Pages. It wants master/docs as its source, or else.
June 10, 2020 20:59
Eliminating "master" is a great idea. Thanks, Scott, for raising this issue! The highly charged and negative reaction to this is further sad proof of how systemic and institutionalized racism is.
Ron
June 11, 2020 0:13
I'm glad I never got a master's degree in college!

As others have pointed out, the term "master" in the context of git has nothing to do with slavery.

People here saying that it costs nothing to change are flat out wrong. Organizations would have to pay developers to do all these steps and deal with all the unforseen side-effects (such as the aforementioned GitHub Pages incompatibility). Orgs that are now facing budget cuts and/or layoffs due to COVID-19 shutdowns destroying their revenue. (And NOW the World Health Organization is saying that asymptomatic carriers are very unlikely to spread the disease, meaning that the shutdowns were completely unnecessary, and that the economy was destroyed for nothing.) They don't have spare resources to waste on idiotic virtue signalling.

When I visited Japan many years ago, I noticed that their maps were covered in swastikas. Now, my grandmother was a Polish Jew who fled from Europe to the US, so understandably I was a little freaked out by this. When I asked someone about the swastikas, they explained that they mark the locations of Buddhist temples. (The Nazis had appropriated this symbol that had been used by othet cultures for thousands of years.) In this context, the symbols had absolutely nothing to do with Nazis so there was no problem. I didn't even occur to me to throw a tantrum and demand they change their maps.
June 11, 2020 2:31
Scott, I believe that this line:

> git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

Can be simplified to

> git remote set-head origin -a

When setting your local clone's default branch.
June 11, 2020 3:08
Actually, I think that only works if you're currently on your default branch.

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.