By default, when you initialize a new git repository, it creates the master branch as the default branch name. You can also initialize a new git repository with a different default branch name than the master.
Using git init -b or –initial-branch=<branch-name> option (git version 2.28.0 onwards):
1 2 3 4 5 6 7 8 9 10 |
## Initialize a git repository (default branch name) git init mydir && cd mydir git status # On branch master cd .. && rm -rf mydir ## Initialize a git repository (non default branch name) ## git version 2.28.0 onwards git init -b debjeet mydir && cd mydir git status # On branch debjeet cd .. && rm -rf mydir |
Using git configuration (git version 2.28.0 onwards):
1 2 3 4 5 6 7 8 9 10 11 |
## Add a new configuration in git config file ## git version 2.28.0 onwards git config --add --global init.defaultBranch debjeet ## Initialize a git repository git init mydir && cd mydir git status # On branch debjeet cd .. && rm -rf mydir ## Delete git configuration in git config file git config --global --remove-section init |
Using git template (all git versions):
1 2 3 4 5 6 7 8 9 10 11 12 13 |
## all git versions ## Add a new configuration in git config file mkdir ~/Templates git config --global init.templateDir '~/Templates/git.git' cp -r /usr/share/git-core/templates ~/Templates/git.git echo 'ref: refs/heads/debjeet' > ~/Templates/git.git/HEAD git init mydir && cd mydir git status # On branch debjeet cd .. && rm -rf mydir ~/Templates ## Delete git configuration in git config file git config --global --remove-section init |