Is it possible to view multiple git branches at the same time for the same project?
I have 2 branches, which are not ready to be merged yet, but have some complementary logic, which I'd like to review (before merging)
Can I check out multiple git branches of the same project? Is it possible?
You can simply copy the repository to a new location (either by literally copying the directory, or using git clone --shared
) and check out one branch per location.
You can also use git-worktree
for creating multiple working directories from a single instance of a repository.
Otherwise, the primary means for comparing files between branches prior to merging them is git diff
.
With Git 2.5+ (Q2 2015), a Git repo will support multiple working trees with git worktree add <path>
(and that will replace contrib/workdir/git-new-workdir
)
Those "linked" working trees are actually recorded in the main repo new $GIT_DIR/worktrees
folder (so that work on any OS, including Windows).
See more at "Multiple working directories with Git?"
Yes it is possible with appropriate care. However you are taking one of the copies 'away' from the regular git directory using --work-tree=<path>
option, so changes there won't be seen by git unless you specially tell it. I gave an example here single-working-branch-with-git - see the UPDATED segment.
Note that the git-new-workdir
doesn't work on Windows XP as it requires Unix style links.