Created
April 8, 2011 02:54
-
-
Save cj/909201 to your computer and use it in GitHub Desktop.
This file contains 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/sh | |
# | |
# merge [branchname] | |
# | |
# Tries to merge local branch "branchname" into master, | |
# regardless of what branch you are currently in. | |
# It will stop you if you are behind & need to pull 1st | |
# | |
remote="origin" | |
branch=$1 | |
current_branch=$(git branch 2>/dev/null|grep -e ^* | tr -d \*//) | |
if [ -z $branch ]; then | |
echo "Usage: $0 [branchname]" | |
exit 1 | |
fi | |
# If there is a remote version of this branch, rebase onto current_branch first | |
# If there's a remote (public) branch, we do not want to be rewriting histories | |
tracking=$(git branch -vv | egrep "^\*" | awk '{ print $4 '}) | |
echo "tracking=$tracking" | |
if [[ ! "$tracking" =~ "$remote" ]]; then | |
echo "* Local-only branch, rebasing $branch onto $current_branch first..." | |
git checkout $branch | |
git rebase $current_branch || exit 1 | |
else | |
echo "* This branch exists remotely, not rebasing" | |
fi | |
echo "* Merge $branch into $current_branch" | |
git checkout $current_branch | |
git merge $branch || exit 1 | |
# Idea: delete local and/or remote branch (?) | |
# echo "* Deleting merged local branch..." | |
# git branch -d $branch || exit 1 | |
echo "* Done" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks cj, I finally merged this into git-friendly mainline