DEV Community

Cover image for Renaming your master branch to main in GithubπŸ‘©β€πŸ’»
Jane Tracy πŸ‘©πŸ½β€πŸ’»
Jane Tracy πŸ‘©πŸ½β€πŸ’»

Posted on • Updated on

Renaming your master branch to main in GithubπŸ‘©β€πŸ’»

How I learned about the main branch

When I started to code in March this year, I have always used the master branch as my default branch. From all the tutorials I learned from Youtube or Tech blogs, they all used the master branch. I never had any clue that you can change it until recently(Talking about being a newbie, no judgment here 😁). Last week, when I was contributing to an Open Source project in Github, one of the issues was changing the master branch to main and also the existing open pull requests. At first, I didn't understand but I decided to do my research.

internet gif

PS: That's why I started to love open source contribution, I get to learn a lot from more experienced engineers.

After a while, I found different ways to rename your master branch, from using Git or just changing a few things in your GitHub account.
Something to note my newbies, the owner of the GitHub repository is the only person who can change the default branch. You can't do it from a pull request for open source contribution.

Step 1 - Changing your upcoming repositories to the main branch as a default.

  • Click your profile icon on the top right

Profile icon in Github

  • Click on the settings

Settings image in Github

  • Go to the Repositories tab.

Here we are going to change the default branch of all your new personal repositories that you will be creating. You can also change the default branch in each repos individually (I will show you how to do it in step 2).
Just create a new default branch and click the update button. For me, I went with the main branch.
With this step, any new repository you will create in Github, it will have the main branch as the default branch.

Repository tab image

A quick step

When creating a new repository you will see some text from Github, just above the create a repository button, which directs you to change your default branch directly. (This will set main as the default branch. Change the default name in your settings.)
Github account image

Step 2 - Updating your existing repository and the open pull requests to the main branch.

In this step, you can use git or just change it from Github directly.

Using Github directly
  • Click on the master branch and create a new branch called main. The main branch will be equal or have the same code as your master branch. (Don't panic your code files will still be the same.)

Creating the main branch

  • Click on the setting tab of your repository
    setting tab image

  • Select the branches tab in the left menu
    When you select the master option you will a drop-down of the branches you created. Since we want to change the default branch to main, you will select the main branch. Then you will click on the update button on your right.
    Github branches tab

You will see a warning alert that if you change your default branch your open pull requests will be affected. Just click the I understand button and you have finally updated your default branch.

  • Delete the master branch Let's just say, I didn't know how to delete a branch from GitHub, I only used Git. (It's called beginner struggles don't laugh too hard. πŸ€¦β€β™€οΈ) We learn as we engage in different projects don't put yourself down.

Click the branches tab
Branches tab in the repo

Go and select the delete icon on the master branch
Delecting the master branch

How to update your existing pull requests

This time we are using Git to change our branch to set the existing pull request to the main branch. This action was created by Edward Thomson who works at Github. He has amazing projects go check them out and one of them is a node package - retarget prs that helps to update your open pull request to the main branch.

Steps to take

After you have created and set the main branch as the default, do the following:

Install Node Js software if you don't have it
Create a personal token

It is used for authentication and can be used instead of a password in Git over HTTPS.

  • Go to your profile pic and click settings.
    On the left side menu, select the Developer settings tab.
    Developer settings

  • Click on the personal access token tab.
    Select the Generate new token button to create a token.

Personal access token tab

  • Check on the boxes on that define the access of your personal token. You can also name the token. For this example, I named it awesome notes. (It's good to confuse people, who love snupping in your things/account.) After you are done selecting the checkboxes, click on the green Generate token button which will be at the bottom and our token will be generated. It will contain numbers and letters plus it's long, copy it somewhere safe. (You won't remember it off-head unless you are a genius or something. 😜)

Personal token generation

Please note: You should not share your token with anyone. Keep it somewhere you know it's safe.

  • Go to your Git terminal and write the following
npx retarget_prs --token your_pat master main
Enter fullscreen mode Exit fullscreen mode

Replace your_path with your GitHub token and paste in your repo URL.


You have moved your open pull requests to the new default main branch.

Congratulations gif

Update from Github

Github is an amazing organization, the changes will begin next month.

On October 1, 2020, any new repositories you create will use main as the default branch, instead of master. This change does not impact any of your existing repositories: existing repositories will continue to have the same default branch they have now. You can opt-out of this change at any time.

For more details about the changes you can follow Github repository

Github message on the Main branch

In Conclusion

You can now go and change your default branch easily with the above simple steps. Always remember you learn as you get more exposure to different projects, don't be so surprised when you hear or see something you don't know or never heard about.

If you find this post useful share it with your peers or beginners who want to start open-source contribution. You can also buy me a Cappuccino. πŸ™‚

Buy Me A Coffee

Discussion (22)

thinkverse profile image
Kim Hallberg

Git v2.28 introduced the init.defaultBranch config so now you can also set it locally as well. πŸ‘Β πŸ™‚

$ git config --global init.defaultBranch main
Enter fullscreen mode Exit fullscreen mode

Github wrote a blog post about that you can read - "Introducing init.defaultBranch". πŸ˜€

tracycss profile image
Jane Tracy πŸ‘©πŸ½β€πŸ’» Author

Thank you, Kim, for adding that.
I didn't know about it. πŸ”₯

tcelestino profile image
Tiago Celestino

It's nice!!!

goodevilgenius profile image
Dan Jones

I will continue to maintain that main is not a useful name. Neither is master, and has other problematic implications. So, I'm certainly not advocating using master.

The thing is, we name all of our other branches according to their purpose, so why not the default branch? In my opinion, the default branch should also be named according to how it's used.

For projects where the default branch represents the stable code, it should be named something like stable, or prod. I usually use prod for continuously deployed web apps, and stable for versioned projects.

For projects where the default branch represents the main development branch, it should be named develop or development.

alec profile image
Alexey Poimtsev (sith/lord)

You better try git-flow principles :)

goodevilgenius profile image
Dan Jones

I do. In all my projects. πŸ˜ƒ

tracycss profile image
Jane Tracy πŸ‘©πŸ½β€πŸ’» Author

Thanks for your input, Dan. βœ”
Yes, it's true.
Different teams or organization name their branches differently. πŸ’―πŸŒŸ
Develop branch is common especially for features underdevelopment etc.

alec profile image
Alexey Poimtsev (sith/lord)

Thanks a lot fot your article! Now I changed main back to master! There's several reasons:
1 - Github changed default settings without asking my permissions for that
2 - in Russian (my native) language word "master" means "expert in his area", but "main" means "basic"
3 - i completely disagry with this new SJW-trends. Being a developer you better focus on good code, useful projects and doing good stuff, but not which name is better for your github branch - master or main.

nathanhannon profile image
Nathan Hannon • Edited on

Someone created a cool web app/tool to automatically rename the default remote branches in all your repositories:

tracycss profile image
Jane Tracy πŸ‘©πŸ½β€πŸ’» Author

That's amazing. Thanks for sharing Nathan. πŸ™Œ

tracycss profile image
Jane Tracy πŸ‘©πŸ½β€πŸ’» Author

Hey, you can use the link I provided in the post to take a look. πŸ’―

rolfstreefkerk profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
Info Comment hidden by post author - thread only accessible via permalink
Rolf Streefkerk

Thanks for explaining the process, but I'm puzzled as to why a change was needed to begin with.

Within the context of operating Git it's a perfectly acceptable term. but of course we've found ways to link it to slavery so we must "abolish" the term.

To give you some context on how many different meanings this word has, just look at a few dictionaries:

The Free dictionary states; 12. An original, such as an original document or audio recording, from which copies can be made, which is a perfectly suitable explanation for the term Master in the Git system.

panphora profile image
David Miranda

Hi Rolf,
I appreciate your position and actually held it at one point.
Here are some counterpoints:

  1. Recruiting. Let's say you're trying to recruit someone to work with you who is of a different ethnicity or from a marginalized identity (e.g. LGBTQ or differently abled). Don't you think it would make them feel more comfortable if they realized you were making an effort to be more open minded and inclusive, even if that effort (e.g. renaming "master") didn't affect them in particular? It would be a signal that you're at least trying. Renaming "master" to "main" seems like a really small thing to do in order to get across the point that you're building an inclusive and fair environment.
  2. The person who named it "master" in the first place, Petr Baudis, has said that he's "wished many times I would have named them 'main' (and 'upstream') instead" when responding to the community effort to rename "master" to something else.
  3. It's a fact that many terms in technology were named by white males with a lot of priviledge (access to technology at an early age, wealth, lots of connections) and if there would have been a more diverse constituancy in tech as it was being developed, things would have been created and named very differently. It's not fair that an entire ecosystem is biased by one group's worldview β€” and changing this name can be just a small acknowledgement of that unfairness.
  4. There are examples of this in the past, around women's rights as they entered the workforce. The way men casually demeaned women before they entered the workforce was unacceptable before women started working alongside men. Just because the culture shifted and certain ways of speaking became off limits once the workforce got more diverse doesn't mean the people working there shouldn't have been more self-aware and accepting from the start. It shouldn't take something like this to get someone to realize they might be holding onto some internal biases because of the color of their skin or the gender they were born into. Since no one can actually live in other people's shoes, it shouldn't be hard to understand that a term might not be important/meaningful/offensive to one person, but be really meaningful to someone else. If someone says something's important to them, and it isn't to you, why not just go along with them for the sake of being supportive/understanding? That's not such a hard thing to do.
rolfstreefkerk profile image
Rolf Streefkerk

First off I appreciate you're interested in an honest discussion.

Here's the rub I have with "mandated" speech. Terms are used in a very specific context in which they operate and by neglecting or simply ignoring the context we can create meaning out of thin air. That is what's happening here and that's why I have a problem with it.

The term master in the context of Git means just as you've seen in my example and nothing more, I therefore fail to see any relation with minorities or other groups. What we have here is a question of education, once we define what the words mean there can be no confusion to what its intent is.

It's unfortunate that the creator has said that and I do not know the circumstances under which that was said. At any event, it doesn't change the fact that definitions and being precise with language avoids a lot of confusion without us having to mandate speech to avoid people getting their feelings hurt.

Your point about privilege and white males is a construct created by identity politics and race theory. Linking a color of a skin to some kind of privileged position is a massive generalization. Colors do not come into it. There are a vast number of variables that determine success in life and then there's such a thing as plain chance. Where are you born? Were your parents rich? etc. etc. These are all the parts of life that are unfair and we have to accept as something we cannot change.

We are in a free society where people should be judged based on individual actions and not by some group identity.

Finally about women's rights, again you use grouping and mass generalizations to come to quick conclusions. It's just not how the world works. You act like every man out there is out to diminish the chances of every woman. That's just not true and you know that is a fact. Again here, it's individuals that do and do not. It's not groups that do or do not. This is an important distinction.

Please understand your identity politics doesn't solve anything, it will in fact exacerbate issues we have and it will increase tensions among people because we're now being judged on our group identity.

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

I wonder if Git itself will be renamed, with a similar rationale.

tracycss profile image
Jane Tracy πŸ‘©πŸ½β€πŸ’» Author

Thank you for explaining it perfectly.
I appreciate it, David.
Building an inclusive environment is the best for growing the Tech community. πŸ™ŒπŸ‘

tracycss profile image
Jane Tracy πŸ‘©πŸ½β€πŸ’» Author

This post was a tutorial created for people who want to change from the master to the main branch.
If someone doesn't that's up to them.
For me, I wanted to change it to the main branch and also many other engineers are doing it too.
No one is forcing anyone to do something.
As I said this is a tutorial-based post for people who want to rename the master branch and don't know how to do it.

matt123miller profile image
Matt Miller (he/him)

To give you some context on the different meanings of another phrase just look at a dictionary.

rolfstreefkerk profile image
Rolf Streefkerk

I wasn't expecting anything less. The labeling tactic is a familiar one isn't it, now you don't actually have to argue for your position. Much easier that way.

At any event, you don't have to agree with me, have a good one.

rolfstreefkerk profile image
Info Comment hidden by post author - thread only accessible via permalink
Rolf Streefkerk

You mark my reply as non constructive and you dare to edit out my thanks to the Original poster to make it look that way. This post did not start with my comment about the 'Master' reply. This is a new low for this site.

At least have the courtesy of leaving the unedited version if you decide to moderate it.

jgaguiar16 profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
Info Comment hidden by post author - thread only accessible via permalink

Why this comment is marked as low quality/non-constructive? He didn't say something bad, offensive or whatever.

It makes me so angry when someone just say/write something with facts and because those facts goes against other people believe, that for example, the term "master" is offensive or whatever, just cancel it or censorship it,

It's so f toxic.

Some comments have been hidden by the post's author - find out more