git worktrees

Andreas Schneider asn at samba.org
Fri Oct 29 09:31:59 UTC 2021


Hi,

I often have to hop between different branches. Either to fix a bug or to just 
run a test. As Samba doesn't support out of source builds, this was a pain 
till I discovered `git worktree` [1].

git-worktree allows you to have multiple working trees. You can use it with 
any git checkout you have. However to work with it in a nice manner, the right 
thing is to use a bare repository. Here is how this works:

Setting up the directory for the first time:

mkdir samba
cd samba
git clone --bare https://git.samba.org/samba.git .bare
echo "gitdir: ./.bare" > .git

Now you can create a branch and check it out:
git branch asn-mywork origin/master
git worktree add mywork asn-mywork

This will create a directory `mywork` and checkout the branch `asn-mywork`

cd mywork

Now you can start breaking Samba ... :-)


I've created two aliases:

[alias]
     wtb = "!f() { git branch $1 $2; git worktree add $1 $1; }; f"
     wtr = "!f() { git worktree remove $1; git branch -D $1; }; f"

Hope this is useful for others too, metze already uses it ;-)


	Andreas


[1] https://git-scm.com/docs/git-worktree


-- 
Andreas Schneider                      asn at samba.org
Samba Team                             www.samba.org
GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D





More information about the samba-technical mailing list