New Repo with Main Branch - Samvera Branch Renaming Working Group

Upgrade git

The ability to use an alternate name for the primary branch began in git release 2.28.  There are several ways to update git.  I used Homebrew on a Mac.

$ git --version
git version 2.17.2 (Apple Git-113)
$ brew install git
...
$ git --version
git version 2.17.2 (Apple Git-113)


NOTE: The version didn't change even though brew installed the latest version.  If this happens, you may need to update the PATH.  I did the following to fix the problem.

Edit ~/.bash_profile

Add the following line near bottom of this file...

# required for git installed by Homebrew to be found
export PATH="/usr/locl/bin:${PATH}"

and execute the following to activate this change...

$ source ~/.bash_profile
$ git --version
git version 2.28.0

NOTE: You have to execute the source command in every terminal tab or restart terminal to have it fully take effect.

Configure main as the default repository for all new repos


$ git config --global init.defaultBranch main


This updates ~/.git file and adds the following lines...

[init]
        defaultBranch = main

Create repo with new default branch name

$ mkdir myapp
$ cd myapp
$ git init
Initialized empty Git repository in ...
$ git status
On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

Add repo to GitHub

Create the repo in GitHub without adding any files (README, License, .gitignore).  If you allow Github to add files, they will be added to the master branch.

echo "# myapp" >> README.md
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/your_organization/myapp.git
git push -u origin main

NOTE: All of this is listed on the new repo page in github when you create the repo.  EXCEPT the last line which specifies main as the branch instead of the default master branch provided by github.

Observations and confirmations:

  • Refresh repo page in GitHub and you will see the main branch selected with README.md as the only file.
  • Selecting the branch drop down list, you will see that main is the only branch.
  • ... → Settings → Branches
    • under the Default branch section, you will see "The default branch is set to main."