Tuesday Tips

GitGitHub

Recent events have brought to light the negative connotations of having the main branch on a repository called master. Whether you want to change your primary branch name for this reason or just for fun, it is important to know how to do so and there are a few key steps to ensure that the change goes smoothly.

Changing Future Repositories

Before we jump into changing our existing repos, let's make sure that we avoid the issue altogether in our future projects. In GitHub, under Settings > Repositories there is an option to name your default branch for future projects. Remember, this changes it for your personal account, but you can do the same for an organization.

As a note, on October 1st of this year, GitHub will be setting the default branch for new repositories to main.

Updating Existing Repos

Now, to change an existing repo to a new name add a new branch from the existing master, which we will call main for this example. With an exact copy now on main go to the repository Settings > Branches and change the default branch to main. Then we can delete the master branch, which will alert us that the open pull requests for master will be affected. You can use a tool, like this one from Edward Thomson, to re-target the pull requests to the new branch.

And that's it! You've made the change away from the master branch. If you still think it sounds a bit too complicated or too much work, GitHub announced that it will be releasing a feature to make a seamless transition when renaming the default branch by the end of the year.

Credit

Today's Tuesday Tips was adapted from a post on the DEV Community.