git working on two branches simultaneously

Viewed 97462

I have a project with many branches.

I would like to work on several branches simultaneously without switching back and forth with git checkout.

Is there any way I can do that besides copying the whole repository somewhere else?

6 Answers

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.

Here's a scalable version of the accepted answer (upvoted), with sequentially named branches (app1..app10).

Note we should try to avoid duplicate checkout (here: by checking out the master branch, which will not be covered by git worktree add):

$ git checkout master && for NUM in {1..10}; do git worktree add ~/git/<repo-name>/app$NUM app$NUM; done

Not really as Git only supports to have one working copy of the repository data within the repository directory.

If you want to commit/pull to the same repository with two different working copies, you could create a bare repository and clone it to two working copies.

Whenever you have finished something, you simply push to the "main" bare repository.

Some hints:

man git-clone

git clone --bare

Related