Easily rename your Git default branch from master to main
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?
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.
> git branch -m master main
> git push -u origin main
Total 0 (delta 0), reused 0 (delta 0)
remote: Create a pull request for 'main' on GitHub by visiting:
* [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.
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.
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
- Go to the master branch
- Rename master to main locally
- Get the latest commits from the server
- Remove the link to origin/master
- Add a link to origin/main
- 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.
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.
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 ✊🏿
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.
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?
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.
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.
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.
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.
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
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.
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.
In other words, can I name someone a master (to emphasise someones skills) and became an offensive person/racist?
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.
Also did not know about the -u shortcut
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?
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:)
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.
git config --global alias.new '!git init && git checkout -b main && git commit --allow-empty -m \"new\"'
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.
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?
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.
"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.
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.
> 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.
Comments are closed.