Skip to content

Instantly share code, notes, and snippets.

@mgaitan
Last active December 16, 2015 08:39
Show Gist options
  • Save mgaitan/5407084 to your computer and use it in GitHub Desktop.
Save mgaitan/5407084 to your computer and use it in GitHub Desktop.
Integrate our branch into origin/develop
#!/bin/bash
#
# Integrate our branch into origin/develop
#
# It's a shortcut for :
#
# 1. pull for last changes on develop
# 2. rebase the target branch against develop
# 3. recheck if no changes happen in the meanwhile
# 4. merge --no-ff
# 5. push develop to origin
#
# Usage:
#
# $ git integrate # default current branch
# or
# $ git integrate wonderful_feature_branch # integrate specific branch
#
#
# Install:
#
# Just put this file somewhere in your PATH (i.e. ~/bin,) with +x permission
#
# Author:
#
# Martín Gaitán <[email protected]>
# http://machinalis.com
#
branch=$1
if [ -z $branch ]; then
branch=$(git symbolic-ref -q HEAD)
branch=${branch##refs/heads/}
test -z $branch && echo "Couldn't determine the current branch." 1>&2 && exit 1
fi
echo "Integrating $branch into origin/develop"
git checkout develop
git pull
git checkout $branch
git rebase develop
rebase_exit_status=$?
if [[ $rebase_exit_status != 0 ]]; then
echo "** Rebase fail. Aborting"
git rebase --abort
exit -1
fi
git checkout develop
git fetch origin
reslog=$(git log HEAD..origin/develop --oneline)
if [[ "${reslog}" != "" ]] ; then
echo "** Somebody pushed to develop just before you (ha-ha)!. Please, Try again."
echo "Aborting"
exit -1
fi
git merge --no-ff $branch
git push origin develop
@fjcapdevila
Copy link

Good work! I will test it and post some feedback.
Thanks!

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