I\'m on branch a
. I want to merge branch b
into branch c
. The merge is not a fast-forward, but it also doesn\'t require manual resolut
Additional to the very sophisticated git read-tree
answer by @jthill, there is (nowadays) an IMHO easier way doing this utilising git worktree
.
This is the basic approach:
$ git worktree add /tmp/wt c
$ git -C /tmp/wt merge b
$ git worktree remove /tmp/wt
Below is a little Bash script which you can call like this:
$ worktree-merge c b
worktree-merge
:#!/usr/bin/env bash
log() {
echo -n "LOG: "
echo "$@" >&2
}
escape() {
local string="$1"
echo "${string//[. \/]/-}"
}
cleanup() {
trap "" SIGINT
log "Removing temporary worktree '$1' ..."
git worktree remove --force "$1"
}
prepare_worktree() {
local reference="$1"
local worktree="/tmp/MERGE-INTO-`escape "$reference"`"
log "Creating temporary worktree '$worktree' ..."
trap "cleanup $worktree" EXIT
git worktree add --force "$worktree" "$reference"
}
do_merge() {
local reference="$1"
local worktree="/tmp/MERGE-INTO-`escape "$reference"`"
shift
log "Merging ${@@Q} into ${reference@Q} ..."
git -C "$worktree" merge "$@"
}
prepare_worktree "$1" &&
do_merge "$@" &&
true