Skip to content

Instantly share code, notes, and snippets.

@leth
Created June 15, 2020 09:52
Show Gist options
  • Save leth/8984b74267bdc82dd959930794091f2f to your computer and use it in GitHub Desktop.
Save leth/8984b74267bdc82dd959930794091f2f to your computer and use it in GitHub Desktop.
Create new git repos with a 'main' branch rather than 'master'
# Add this to your .bash_profile
function git_init_fnc () {
\git "$@"
if [[ $1 == "init" ]];then
if [[ -n "$2" ]]; then
git_dir="$2";
else
git_dir=`pwd`;
fi
default_branch="main"
(
cd $git_dir
\git symbolic-ref HEAD refs/heads/$default_branch
)
fi
}
alias "git"=git_init_fnc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment