Skip to content

Instantly share code, notes, and snippets.

@pneff
Created October 5, 2013 09:27

Revisions

  1. pneff created this gist Oct 5, 2013.
    37 changes: 37 additions & 0 deletions fullmerge
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #!/bin/bash
    # Merges a local branch
    set -e

    # Needs a branch name as argument.
    test -n "$1" || exit 1

    # Update master to origin.
    git fetch --no-recurse-submodules
    git checkout master && git merge origin/master
    git checkout $1

    # Check if there are any fixup or squash commits.
    # If so we do an interactive rebase first against the branch-off point to
    # clean up the history.
    branchoff=$(git log --pretty='format:%H' master..HEAD | tail -1)
    if git log --oneline origin/master..HEAD | egrep -q '(fixup|squash)'; then
    git rebase -i ${branchoff}^1
    fi

    # Now rebase this branch to master. Also force-push to origin, so GitHub
    # correctly recognizes this branch as merged later and closes the pull request.
    git rebase master
    git push origin $1:$1 -f

    # Merge the branch into master.
    git checkout master
    git merge --no-ff $1
    git push origin master

    # Clean up the branch locally and remotely. You can always get it back with
    # reflog if needed.
    git branch -d $1
    git push origin :$1

    # Bye bye, it was a plasure having you.
    echo done