I have 2 branches, the main
one and the one I'm working on a parallel
release.
A --> B --> C (master)
\
-> E --> F (parallel)
The parallel
branch will always merge from master
. Always. And modify upon it.
A --> B --> C --> D --> H (master)
\ \ *merge*
-> E --> F --> G --> J (parallel)
This is easy to do if I switch branches.
But, if I'm working on parallel
, can I do this without switching branches? The problem with switching is that it takes a long time to go back and forth (specially on Unity 3D)!
So say I'm on F
, while master is still on A
. Then I wanted to make few commits on master B
and C
then merge them into G
. How would I do it, again, without switching branches?
There is (nowadays) a much easier solution utilising
git worktree
: You will get additional worktrees (i.e. checkouts), but sharing the same repository data.The manpage states:
That means you do not need to switch branches but just change directories when "switching" your activities from
master
toparallel
or vice-versa. Since there is no additional (cloned) repository, there is no overhead in managing it like push, merge or fetch operations as well as no configuration hassle.Add an additional worktree for branch
parallel
:To work simultaneously on two branches, push between paralleled clones.
Switch to master:
Switch back:
and that's all it takes,
git merge
works normally. If you're ever going to merge from parallel to master, just push the other way before switching, it works the same both ways.What you want could possibly be achieved using low-level (plumbing) Git commands and a separate work tree and the index.
As explained in the
git(1)
manual page, through the usage of environment variables it's possible to make a separate work tree for a given Git repository, basically:Now update the files in the work tree and stage the changes (
git add
etc) and thenThis:
git write-tree
) and writes its SHA-1 name to stdout.This operates on a pretty low level using only the plumbing commands but not touch
HEAD
in the repository and hence allows to work normally in the original work tree.This is scriptable but is too cumbersome so I'd just try to use the
git-new-workdir
script available in thecontrib
section of the Git proper — it sets up a separate work tree linked to the original repository excluding the crucial stuff likeHEAD
which might disrupt the work in the original work tree. So you could create the new work tree, check out "master" into it, record new commits on it then safely merge them in the original work tree which has "parallel" checked in.