Skip to content

Instantly share code, notes, and snippets.

@tunnckoCore
Forked from jnsahaj/.zshrc
Created January 17, 2026 02:26
Show Gist options
  • Select an option

  • Save tunnckoCore/a2b7b20f8bbabaf92b7619a50c42ec61 to your computer and use it in GitHub Desktop.

Select an option

Save tunnckoCore/a2b7b20f8bbabaf92b7619a50c42ec61 to your computer and use it in GitHub Desktop.
Peter Steinberger's Multiple Checkout aliases
# Create a new clone and branch for parallel development.
# Usage: ga <branch-name> [base-branch]
ga() {
if [[ -z "$1" ]]; then
echo "Usage: ga <branch-name> [base-branch]"
return 1
fi
local branch="$1"
local repo_name="$(basename "$PWD")"
local repo_url="$(git remote get-url origin)"
local clone_path="../${repo_name}-${branch}"
# Use fzf to select base branch, defaulting to main
local base_branch="$(git branch -r --format='%(refname:short)' | sed 's|origin/||' | fzf --height=20 --prompt='Select base branch: ' --query="main")"
# If fzf was cancelled, fall back to main
if [[ -z "$base_branch" ]]; then
base_branch="main"
fi
echo "Creating clone at $clone_path from $base_branch..."
# Clone with reference to current repo for speed/space savings
git clone --reference "$PWD" "$repo_url" "$clone_path"
# Enter clone and set up branch
cd "$clone_path"
git checkout "$base_branch"
git checkout -b "sj/$branch"
echo "Created clone at $clone_path on branch sj/$branch (based on $base_branch)"
}
# Remove a cloned repo directory. Warns if there are uncommitted changes.
# Run from within the clone you want to delete.
gd() {
local cwd="$(pwd)"
local clone_name="$(basename "$cwd")"
# Check for uncommitted changes
if [[ -n "$(git status --porcelain 2>/dev/null)" ]]; then
echo "⚠️ Warning: You have uncommitted changes:"
git status --short
echo ""
if ! gum confirm "Delete anyway?"; then
echo "Aborted"
return 1
fi
fi
# Check for unpushed commits
local unpushed="$(git log --oneline @{upstream}..HEAD 2>/dev/null)"
if [[ -n "$unpushed" ]]; then
echo "⚠️ Warning: You have unpushed commits:"
echo "$unpushed"
echo ""
if ! gum confirm "Delete anyway?"; then
echo "Aborted"
return 1
fi
fi
if gum confirm "Remove clone '$clone_name'?"; then
cd ..
rm -rf "$clone_name"
echo "Removed $clone_name"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment