Created
July 16, 2024 07:00
-
-
Save peterneave/3f9514f66de59599f9a8cdfc74a4a443 to your computer and use it in GitHub Desktop.
Setup Git Worktree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# Examples of call: | |
# git-clone-bare-for-worktrees [email protected]:name/repo.git | |
# => Clones to a /repo directory | |
# | |
# git-clone-bare-for-worktrees [email protected]:name/repo.git my-repo | |
# => Clones to a /my-repo directory | |
url=$1 | |
basename=${url##*/} | |
name=${2:-${basename%.*}} | |
mkdir $name | |
cd "$name" | |
# Moves all the administrative git files (a.k.a $GIT_DIR) under .bare directory. | |
# | |
# Plan is to create worktrees as siblings of this directory. | |
# Example targeted structure: | |
# .bare | |
# main | |
# new-awesome-feature | |
# hotfix-bug-12 | |
# ... | |
git clone --bare "$url" .bare | |
echo "gitdir: ./.bare" > .git | |
# Explicitly sets the remote origin fetch so we can fetch remote branches | |
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" | |
# Gets all branches from origin | |
git fetch origin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From Workarounds to Git worktree using bare repository and cannot fetch remote branches