DevOpsOpen Source SoftwareTutorials

How to configure the default branch name in git command line

Starting with Git 2.28, you can globally define the default branch:

git config --global init.defaultBranch main

Alternatively, you can edit the global .gitconfig file and add

[init]
       defaultBranch = main

The next time you initialize a local repository, it looks like this

➜  swiss-meetup-2021-jan git init
Initialized empty Git repository in /Users/mfriedrich/dev/work/gitlab-de/swiss-meetup-2021-jan/.git/
➜  swiss-meetup-2021-jan git:(main) βœ—

Next, add & commit any changes and configure the remote origin.

git remote add origin https://gitlab.com/gitlab-de/swiss-meetup-2021-jan.git

git push -u origin main

Push the remote branch. It may be needed to update the local-remote tracking with "-u".

You may also like

Leave a reply

Your email address will not be published. Required fields are marked *

More in:DevOps