Skip to content

Instantly share code, notes, and snippets.

@paulredmond
Created December 18, 2015 20:45
Show Gist options
  • Save paulredmond/350f67e4564e5c8b0560 to your computer and use it in GitHub Desktop.
Save paulredmond/350f67e4564e5c8b0560 to your computer and use it in GitHub Desktop.
Rebuild an integration branch from master and reapply branches previously merged into integration but that have not been merged to master
#!/usr/bin/env bash
# Update the origin remote and prune it
updateOrigin()
{
git fetch origin
git remote prune origin
}
# List branches that are merged into integration, but not master
listBranches()
{
comm -12 \
<(git branch -r --no-merged origin/master | sort -d | grep origin) \
<(git branch -r --merged origin/integration | sort -d | grep origin) \
| grep -v origin/integration \
| awk '{ print $1 }'
}
usage()
{
echo "integrate [list|rebuild]"
}
case $1 in
rebuild)
echo "Updating and pruning origin"
updateOrigin
echo "Updating local integration branch"
git checkout --quiet master
git branch -D integration
git checkout -b integration origin/integration
echo "Checking for an existing integration-backup branch."
git show-branch integration-backup 2> /dev/null
if [ $? -eq 0 ]
then
echo "deleting local integration-backup branch"
git branch -D integration-backup
fi
echo "Creating an integration-backup from integration"
git branch integration-backup integration
echo "Hard resetting integration to master"
git reset --hard origin/master
echo "Trying to automatically re-merge branches into integration"
git merge $(listBranches) && exit $?
;;
list)
echo "Updating and pruning origin"
updateOrigin
echo
echo "Branches merged into integration but not master:"
echo "-----"
listBranches
echo "-----"
exit 0;
;;
esac
echo "Usage: $(usage)"
@paulredmond
Copy link
Author

The goal if this is to try and ease the pain of constantly reintegrating git branches that need to be integrated together, but that are not ready for master yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment