Skip to content

Instantly share code, notes, and snippets.

@justanotherdot
Created June 16, 2020 05:31
Show Gist options
  • Save justanotherdot/f5823c95fb7ffa2a4b64c6da0c434e4b to your computer and use it in GitHub Desktop.
Save justanotherdot/f5823c95fb7ffa2a4b64c6da0c434e4b to your computer and use it in GitHub Desktop.
Change `git init`s default behavior to use `main` branch.
#!/bin/sh -eu
echo '=== Changing `git init` to default to "main" branch.'
echo "+ Updating ~/.gitconfig"
cat <<'EOF' >> ~/.gitconfig
[init]
templateDir = ~/.config/git/template/
EOF
ROOT_TEMPLATE_DIR=""
if [ "$(uname)" = "Darwin" ]; then
ROOT_TEMPLATE_DIR=/Library/Developer/CommandLineTools/usr/share/git-core/templates/
elif [ "$(uname)" = "Linux" ]; then
ROOT_TEMPLATE_DIR=/usr/share/git-core/templates
fi
if [ -z "$ROOT_TEMPLATE_DIR" ]; then
echo "No root template directory. Stopping."
exit 1
fi
cp -r "$ROOT_TEMPLATE_DIR" ~/.config/git/template
echo "+ Updating ~/.config/git/template/HEAD"
cat <<'EOF' > ~/.config/git/template/HEAD
ref: refs/heads/main
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment