From 6faed4df928f3b963091edac10b112690b532c5a Mon Sep 17 00:00:00 2001 From: Tony Miller Date: Tue, 9 Dec 2025 12:42:19 +1000 Subject: [PATCH] add git alias for worktree workflows --- .local/bin/git-cln | 2 ++ .local/bin/git-worktree-setup.sh | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 .local/bin/git-cln create mode 100644 .local/bin/git-worktree-setup.sh diff --git a/.local/bin/git-cln b/.local/bin/git-cln new file mode 100755 index 0000000..7481364 --- /dev/null +++ b/.local/bin/git-cln @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +sh ~/.local/bin/git-worktree-setup.sh "$@" diff --git a/.local/bin/git-worktree-setup.sh b/.local/bin/git-worktree-setup.sh new file mode 100644 index 0000000..2e61811 --- /dev/null +++ b/.local/bin/git-worktree-setup.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -e + +url=$1 +basename=${url##*/} +name=${2:-${basename%.*}} + +mkdir -p "$name" +cd "$name" + +git clone --bare "$url" .bare +echo "gitdir: ./.bare" > .git + +git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" +git fetch origin + +default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') +git worktree add "$default_branch" + +osascript -e "tell application \"Terminal\" to do script \"cd '$PWD/$default_branch' && clear\" in front window"