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 ...

Get Git: Mastering Version Control now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.