Configure a New Github Repo to Use a Different Default Branch

Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

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.

egghead
egghead
~ 13 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today