git merging branches in a bare repository

Note, this can actually be done on a bare repo, but you have to work around the normal interface.

$ git read-tree -i -m branch1 branch2
$ COMMIT=$(git commit-tree $(git write-tree) -p branch1 -p branch2 < commit message)
$ git update-ref mergedbranch $COMMIT

Update: since git 2.38, “git merge-tree” has a new mode to do this, using the same machinery as “git merge”. From the usage section of the manpage:

NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
test $? -eq 0 || die "There were conflicts..."
NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
git update-ref $BRANCH1 $NEWCOMMIT 

Leave a Comment