Configure a New Github Repo to Use a Different Default Branch

Share this video with your friends

Social Share Links

Send Tweet

By default, git provides master as the default branch. This lesson shows how to get round that and use an alternative as the default branch.

The key is to switch to a new branch before you add your first commit, I choose main in this lesson. When I push main up to Github as the first branch, it gets set to the default.

Kevin Cunningham: [0:00] First, set up a new-repo in GitHub, You're presented with these series of commands to be able to commit your repository and get things going. Let's follow them.

[0:11] First thing we're going to do is we are going to add a line to a file called readme.md. This is going to have this #new-repo. Next, we're going to init git, so that's git init. Git automatically begins with the master branch, which is what we want to get away from.

[0:31] What we are going to do is we are going to checkout -b. I want to use the main branch. Other people use production or prod, or some other name to replace the master branch, git add README.

[0:49] I'm going to commit with a message, "First commit." Next, I'm going to add my remote origin as the repo that I've created and then instead of git push -u origin master, I'm going to git push -u origin main. If I refresh the page, you can see I have the main branch and no other branch exists.