Created
October 5, 2013 09:27
-
-
Save pneff/6838763 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
: