Skip to content

Instantly share code, notes, and snippets.

@pneff
Created October 5, 2013 09:27
Show Gist options
  • Save pneff/6838763 to your computer and use it in GitHub Desktop.
Save pneff/6838763 to your computer and use it in GitHub Desktop.
#!/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
@pneff
Copy link
Author

pneff commented Oct 5, 2013

This is the script I use to merge local branches into master.

I have this in ~/bin/fullmerge but also defined a git alias by adding the following into ~/.gitconfig:

[alias]
    fullmerge = !fullmerge \"$1\"

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