At work, I have a project that it has two different version with some common basic features. I make use of git worktree
to put these versions in separate folders that I have two long-running branches beside master
for each version and the master
is for common features. So there are 3 folders with one repository. Also, there is a remote repository for this and the whole things are pushed there.
$git branch -a
*master
version-1
version-2
remote/origin/master
remote/origin/version-1
remote/origin/version-2
At home PC, I have the folder of master
and this local repository is linked to the same remote as my work repo. And when I get the list of branches it is like:
$git branch -a
*master
remote/origin/master
remote/origin/version-1
remote/origin/version-2
I want to checkout
to the version-1
as well as copy the whole stuff of version-a to a local folder, that the folder is tracked by git as a worktree
like at my work.
does git clone
or git checkout
do that or I need to do something more tricky?
Finally I use this to have the same work-trees like at my work, at my home.
$ git worktree add --checkout ../version-1 version-1
$ git worktree add --checkout ../version-2 version-2
It checkout my long-running branches in different folders(work-trees).