Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git working on two branches simultaneously

Tags:

git

branch

People also ask

Can you work on 2 git branches at the same time?

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.

Can we have 2 master branches in git?

You can have a single release/develop/master branch as long as the two products are on the same release cycle e.g., version 2.0 ships at the same time.


Git 2.5+ (Q2 2015) supports this feature!

If you have a git repo cool-app, cd to root (cd cool-app), run git worktree add ../cool-app-feature-A feature/A. This checks out the branch feature/A in it's own new dedicated directory, cool-app-feature-A.

That replaces an older script contrib/workdir/git-new-workdir, with a more robust mechanism where those "linked" working trees are actually recorded in the main repo new $GIT_DIR/worktrees folder (so that work on any OS, including Windows).

Again, once you have cloned a repo (in a folder like /path/to/myrepo), you can add worktrees for different branches in different independent paths (/path/to/br1, /path/to/br2), while having those working trees linked to the main repo history (no need to use a --git-dir option anymore)

See more at "Multiple working directories with Git?".

And once you have created a worktree, you can move or remove it (with Git 2.17+, Q2 2018).


Take a look at $GIT_SRC_DIR/contrib/workdir/git-new-workdir.

According to the commit logs from a port of this repository:

a simple script to create a working directory that uses symlinks to point at an exisiting repository. This allows having different branches in different working directories but all from the same repository.


Git supports multiple worktree at the same time. For more information see:

  • Multiple working directories with Git?
  • https://git-scm.com/docs/git-worktree

How ever it is very hard to support multiple worktree with IDs. For example this is an enhancement request in JGet (eclipse ID) to support worktree.

So, you have to manage project manually (command line) with lots of problems or work with a single worktree in an IDE.