Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 271
James Raitsev Avatar asked Sep 12 '11 20:09

James Raitsev


People also ask

Can I have two git branches open at once?

You can have many branches in your repository, but only one of these will be "checked out" as the working-tree so that you can work on it and make changes. git worktree adds the concept of additional working trees. This means you can have two (or more) branches checked-out at once.

How can I work on multiple branches at the same time?

So you can work on two branches simultaneously. One small catch is that you can't have the same branches checked out in different worktrees. So if you have checked out one branch in one worktree, then the same branch can't be checked out in another different worktree. Another catch is worktrees sync up with each other.


2 Answers

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.

like image 145
meagar Avatar answered Nov 08 '22 08:11

meagar


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?"

like image 42
VonC Avatar answered Nov 08 '22 07:11

VonC