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 to switch to a different branch (for example, to urgently fix a security bug), but your current working directory, and possibly also the staging area, is in a state of high disarray. Instead of disturbing it, you create a temporary linked working tree to make a fix, and remove it when done.

This is an evolving area—consult the Git documentation for more information.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset