I want to checkout multiple branches of the same git repostiory on the same Computer (Linux and Windows). However as the repository might be huge, I would prefer to have the repository once and only multiple working directories.
Is this possible?
How so?
It is possible since Git 2.5 and its git worktree
command.
It replaces an older script contrib/workdir/git-new-workdir
, with a more robust mechanism where those "linked" working trees are actually recorded in the main repo new $GIT_DIR/worktrees
folder (so that work on any OS, including Windows).
Once you have cloned a repo (in a folder like /path/to/myrepo
), you can add worktrees for different branches in different independent paths (/path/to/br1
, /path/to/br2
), while having those working trees linked to the main repo history (no need to use a --git-dir
option anymore)
See "Multiple working directories with Git?"