Skip to content

Instantly share code, notes, and snippets.

@tnarihi
Last active August 29, 2015 14:17
Show Gist options
  • Save tnarihi/19682263b8de7ccb0c0d to your computer and use it in GitHub Desktop.
Save tnarihi/19682263b8de7ccb0c0d to your computer and use it in GitHub Desktop.
A script to interactively git-merge multiple future branches.

A script to interactively git-merge multiple future branches

This is usefull when you are working with open source codes and you have several future branches that you want to use and is still not merged to the main stream.

Workflow:

  1. Edit variables BASE_BRANCH and BRANCHES
  2. Run ./future.sh
  3. If you see conflicts, fix them and commit, then run ./future.sh again.
  4. Repeat 3, until you see the message Done. in the result of ./future.sh.
#! /bin/bash
# Workflow:
#
# 1. Edit variables BASE_BRANCH and BRANCHES
# 2. Run `./future.sh`
# 3. If you see conflicts, fix them and commit, then run `./future.sh`.
# 4. Repeat 3, until you see the message `Done.` in the result of `./future.sh`.
BASE_BRANCH="upstream/master"
BRANCHES="origin/accum-grad origin/share-blobs-over-nets origin/pythonlayer-parameter origin/python-gpu-full origin/future-misc"
STATEFILE=".futurestate"
git status | grep "^You have unmerged paths.$" > /dev/null && { echo "**Fix conflicts and commit to conclude merge, then run this command again.**"; git ls-files -u | sed "s/\s/ /g" | cut -d" " -f4| uniq | sed "s/^/ /g" ; exit 1 ; }
git status | grep "^All conflicts fixed but you are still merging.$" > /dev/null && { echo "**Commit to conclude merge, then run this command again.**" ; exit 1 ; }
if ! [ -e $STATEFILE ]; then
echo "Fetching all remote branches..."
git fetch --all || exit 1
echo "Resetting to $BASE_BRANCH..."
git reset --hard $BASE_BRANCH || exit 1
fi
touch $STATEFILE
for branch in $BRANCHES
do
grep "^running:$branch$" $STATEFILE > /dev/null
if [ "$?" = 0 ] ; then
echo "$branch already applied. skip..."
continue
fi
echo "running:$branch" >> $STATEFILE
echo "Merging $branch..."
git merge --no-ff $branch -m "Merge $branch" || { echo "**Fix conflicts and commit to conclude merge, then run this command again.**" ; exit 1 ; }
done
rm $STATEFILE
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment