DEV Community

Cover image for Replacing master in git
Damien Cosset
Damien Cosset

Posted on • Updated on • Originally published at damiencosset.com

Replacing master in git

Master/slave denomination

The master/slave denomination is a common one in technology. Master/slave is an oppressive metaphor referring to the practice of slavery. These metaphors are inappropriate when describing concepts in technology. They are also inaccurate. Using these metaphors takes away the history of slavery and put it into a context where it does not belong.

UPDATE: People seem to push back on this, for whatever reason... Git's master is historically tied to master/slave. It got the name from BitKeeper. Source here

UPDATE 2: Github is looking to replace the master word

UPDATE 3: This blew up. I'll have to reflect on many things about this subject. I still think that the word should go away from git. Period. However, I was not the right person to brought that kind of topic on the table. I have done harm in the process and I apologize for that. I'm leaving this article up for accountability. Learning to shut up listening and prioritize Black voices is something I will work on.

Words matter. The words we use to define concepts have a lot of importance, even in our tech environment. Git is one of those environments where the word master is still used. But, it's not that complicated to take it away. We have to do two things:

  • Replacing the word on existing branches, both locally and remotely
  • Modify your git configuration to not use the word master when running git init

Let's start with the first point.

Replacing master from your existing projects

First off, we have to change our master branch locally.

Changing master to principal

I have here a project with a master branch. I'm running git branch -m master principal to rename my master branch into the principal one. This command keeps the history of the branch, so you won't lose anything!

Note: I chose to rename the branch as principal. You can choose another name if you wish. It has to make sense for you and your team.

Running git push -u origin principal updates the remote repository by adding the principal branch. The -u flag also sets the upstream.

Change the default branch on Github

Now, I also need to change the default branch on Github. In your repository page, click on the Settings tab, then branches on the left menu. You can update the default branch here:

Updating the default branch on Github

And you are done! If you run git log inside the principal branch, you will see that the history is intact!

Git log on principal branch

We started on origin/master and it properly show that we are on principal now!

Updating local clones

What if someone has a local clone of this repository, how would they correctly update their clone?

This tweet explains you how:


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

Note that the tweet uses the word main to replace master. I'm using principal. Just replace it in the commands with the name you chose.

What these commands do:

  • Go to the master branch
  • Rename the branch to principal
  • Get the latest changes from the server
  • --unset-upstream removes the link to origin/master
  • -u origin/principal creates the link to principal
  • Updates the default branch

Git init

When you run git init, the default branch is master. There are two ways to change that:

Using an alias

You can set up an alias that would run git init while having a other default branch name:

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

Running the above command would allow you to use git new and it would have the principal branch as its default.

You can modify this command of course. Notice the alias.new, this can be change to alias.initialization for example, or whatever command you would like to make. Of course, you can also modify the principal name to fit your needs.

Modifying your git config

We can configure our git to change the default branch.

  • Find the configuration file of your git. It should be either in ~/.config/git/config or ~/.gitconfig.

  • Inside this file, add the following lines:

[init]
    templateDir = ~/.config/git/template/

Now, inside ~/.config/git/template ( you may have to first run mkdir ~/.config/git/template to create it), create a HEAD file and add this line, plus a line break.

ref: refs/heads/principal

When you run git init, the whole contents of the templateDir is copied into .git.

You can now run git init and you will have the branch principal as its default!

Of course, you can change principal to another name if you wish.

Alternative names

I've chosen to use the word principal to replace master here. Here are other words you can use:

  • main
  • primary
  • leader
  • active
  • parent

Just don't use master...

Have fun ❀️
Do no harm.

Sources

Latest comments (238)

 
2colours profile image
2colours

Let me start with the important thing: you are not telling the truth, according to the very source (git log on the repository of git itself) you are reciting; see commit id 08dc26061f3ff9ee79e6cfda88f0c825b8730e54, and in particular, the absolute lack of any occurance of the word "slave" with regards to branches. It's not nice to do these bluffs, counting on the others having good faith for the statement being made, and not bothering to double-check it. :\

For the rest: let's just assume that you were right, as a thought experiment:

Okay, what if it turns out there is a slave card, a slave's degree, a slavepiece, and so on? Does one really just dig down into something that makes sense in good faith, in order to prove that there is something to be offended about? Has anybody even seriously considered what "master branch" is about or is this just a posteriori rationalization?

Also, what if it turns out that the whole master (as opposed to slave) terminology just comes from guild terminology, which in turn comes from being big/great? Excellent, we dug out that there is nothing to be offended about? If there is no politics, that could also be a sensible resolution.

This is the problem with the whole phenomenon. It's not "a bit overboard" but like three steps from common sense. "a bit overboard" is to look for offense when a literal tool, controlled by another tool, is called a "slave". To go ctrl+r over random brands and terms, then retrospectively try to explain the master/slave terminology itself into it, and then implying that this should be offensive and subject to virtue signalling, is much like living in a parallel reality. And these people expect the others to adapt to whatever they make up with this mindset.

Collapse
 
v6 profile image
πŸ¦„N BπŸ›‘

Words are wise men’s counters, they do but reckon by them; but they are the money of fools

--- Thomas Hobbes, (1651), Leviathan (1651) Pt. I, Ch. 4, quoted by Steven Pinker in The Stuff of Thought (2007), p. 151

Collapse
 
bizkut profile image
Hasanuddin Abu Bakar

I am a brown myself but bringing this racist and political shit to the development environment is kinda dumb and lame. Funny enough the white folks who are actually very interested to this movement. For me a brown personally, I don't give a damn.

Collapse
 
jingxue profile image
Jing Xue

I for one look forward to the day when every university stops awarding Master's Degrees. And what kind of messages are we teaching our children when people are still getting Master Plumber or Electrician licenses!

Oh and those jerks in Hollywood also should stop announcing "well we are releasing Star Wars again, ReMASTERed." (Speaking of Star Wars, they'd better re-dub all of them to get rid of all that "one master, one apprentice" nonsense.)

Collapse
 
jenc profile image
Jen Chan • Edited

There is absolutely nothing wrong with bringing this up and leading by example, speaking up about an issue and making the change to make our communities more inclusive. Certainly we can't speak for how all black people feel about this term, but this isn't what you're doing. As allies our responsibility is to educate our own community and it just so happens to be white men and the faction of those who are resistant to change and thinking from other people's perspectives came to dogpile. And sadly this is just one fraction of what outspoken black folks experience. But this is difficult work... and fights have to be picked. There are people who are genuinely interested to discuss and introspect why such a change matters or bothers them. And there's those who are so outraged at any suggestion of change, or just need to be right and pester nonstop.

You're not responsible for how they've reacted. And how you've responded has been generous, human and accomodating. I would also use this energy in your workplace in moments you see that are awry, if someone makes an oddly insensitive joke or is excluded from speaking or meetings, is ridiculed for not knowing something. This is great energy and we need to use it where it matters. Do not apologize and keep pushing!

In the comments I see a range of fragile pushback from centering oneself ("well this never existed in my culture so why should I have to change"), appeal to authority (the authority of black people who only share their point of view, or authority of the creator's non-racist intent), all-or-nothing equivalences ("how about we ban every word with "master" in it too?), trivializing the matter ("this is more political-correctness")... the list goes on. We can feel out when it is useful to engage and when not, because some of these people aren't actually here to talk. You don't owe them an apology at all.

Collapse
 
codemouse92 profile image
Jason C. McDonald

You've done absolutely nothing wrong in bringing this up, so please don't apologize. Thank you for trying to advocate for positive change. It's everyone's responsibility, regardless of color, gender, or nationality.

Some of the negative responses you got on this thread are absolutely beneath the standard of conduct for DEV.

Please keep speaking up for diversity and inclusion! Next time you get attacked like this, don't hesitate to click the three little dots (...) and both Hide Comment and Report Abuse. You have the right to keep conversations on your articles healthy and inclusive...and that means you have the right to be intolerant of intolerance.

 
dimasmagadan profile image
Dmitriy

Ok, you rename that poor master branch
But what you gonna do with this?
github.com/search?q=slave

Collapse
 
dreadknight profile image
Dread Knight

This is silly. Up next: Rip Masters of the Universe and ban chess as well while at it xD
Heck, I'm making a turn based strategy game that's meant to be a modern alternative to chess and it doesn't uses the white/black paradigm anymore, but loosely the colors of the rainbow :D

Collapse
 
cherylcline profile image
Cheryl Cline

Thank you for writing this tutorial.

 
thefern profile image
Fernando B πŸš€

Do as you please, this isn't Facebook. Is a friendly community. Sarcasm on a touchy subject isn't going to get you anywhere. About 90% of your comments are immature as hell, so therefore I rest my case.

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more