Multiple working directories
Git for a long time allowed to specify where to find the administrative area of the repository (the .git
directory) with the git --git-dir=<path> <command>
, or the GIT_DIR
environment variable, making it possible to work from the detached working directory.
To be able to reliably use multiple working directories sharing a single repository, we had to wait until version 2.5 of Git. With it, you can create a new linked work tree by using git worktree add <path> <branch>
, allowing us to have more than one branch checked out. For convenience, if you omit the <branch>
argument, then a new branch will be created based on the name of the created worktree.
Note
If you use an older Git version, there is always the git-new-workdir
script, which can be found in the contrib/
area of the Git project repository. It is however, Unix-only (it relies on symbolic links), and is somewhat fragile.
This mechanism can be used instead of git stash
if you need...