From b35d9a938ad39727afc7ae7eaead2567f4eed46a Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.uk>
Date: Mon, 20 Jul 2020 01:47:30 +0100
Subject: [PATCH] git: Add an init template, use it to create the main branch

See
https://github.com/thoughtbot/dotfiles/commit/56d614f8067c275f4d7b53f3f3a30a5effbeded9.

> This change adds a HEAD file to the Git template with a different ref.
This means that new repositories will commit to a "main" branch by
default instead.
---
 rcrc                        | 1 +
 tag-git/git_template/HEAD   | 1 +
 tag-git/gitconfig           | 3 +++
 tag-zsh/zsh/configs/git.zsh | 8 +-------
 4 files changed, 6 insertions(+), 7 deletions(-)
 create mode 100644 tag-git/git_template/HEAD

diff --git a/rcrc b/rcrc
index edf139ac..ad30da25 100644
--- a/rcrc
+++ b/rcrc
@@ -1,3 +1,4 @@
+COPY_ALWAYS="git_template/HEAD"
 DOTFILES_DIRS="$HOME/dotfiles-local $HOME/dotfiles"
 EXCLUDES="install.sh README.md"
 SYMLINK_DIRS="completion-scripts composer bin functions configs"
diff --git a/tag-git/git_template/HEAD b/tag-git/git_template/HEAD
new file mode 100644
index 00000000..b870d826
--- /dev/null
+++ b/tag-git/git_template/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/main
diff --git a/tag-git/gitconfig b/tag-git/gitconfig
index 91743bc3..319081b3 100644
--- a/tag-git/gitconfig
+++ b/tag-git/gitconfig
@@ -100,6 +100,9 @@
 [include]
 	path = ~/.gitconfig.local
 
+[init]
+	templatedir = ~/.git_template
+
 [merge]
 	ff = only
 
diff --git a/tag-zsh/zsh/configs/git.zsh b/tag-zsh/zsh/configs/git.zsh
index e789c912..e13d94b3 100644
--- a/tag-zsh/zsh/configs/git.zsh
+++ b/tag-zsh/zsh/configs/git.zsh
@@ -1,13 +1,7 @@
 # No arguments: `git status`
 # With arguments: acts like `git`
 g() {
-  if [[ $1 == init ]];
-  then
-    # Prefer "main" to "master"
-    git "$@"
-    git checkout -b main
-    git branch -d master
-  elif [[ $# > 0 ]];
+  if [[ $# > 0 ]];
   then
     git $@
   else