Add another Git shortcut
- ID
5968366- date
2023-01-03 11:38:18+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
fab1391- message
Add another Git shortcut- changed files
1 file, 22 additions
Changed files
git/gm (0) → git/gm (469)
diff --git a/git/gm b/git/gm
new file mode 100755
index 0000000..f5cad91
--- /dev/null
+++ b/git/gm
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+# Switch to my main branch and pull any changes from the remote.
+
+set -o errexit
+set -o nounset
+
+GIT_ROOT=$(git rev-parse --absolute-git-dir)
+
+if [[ -f "$GIT_ROOT/refs/remotes/origin/HEAD" ]]
+then
+ PRIMARY_BRANCH=$(cat "$GIT_ROOT/refs/remotes/origin/HEAD" \
+ | tr '/' ' ' \
+ | awk '{print $5}')
+elif [[ -f "$GIT_ROOT/refs/remotes/origin/live" ]]
+then
+ PRIMARY_BRANCH="live"
+else
+ PRIMARY_BRANCH="main"
+fi
+
+git checkout "$PRIMARY_BRANCH"
+gp