My procedure for doing this kind of thing is similar but avoids the last merge step:

git checkout mybranch
# Make sure the history here is the way I want it to be, e.g.:
git log
git rebase -i HEAD~5
# Now rebase against master
git rebase master
# We'll push this branch to master using a custom command to do it
git pushto master

The script that implements pushto is attached. It has a few nice features. (i) It first shows you what commits will be pushed and then asks you if you want to proceed. (ii) It then pushes the commits one by one, as a way of dealing with the fact that our email script currently sends only one bulk email for the whole push.

Activate the pushto script by putting it in your path and doing:
git config --global alias.pushto=!git-pushto

Richard

#!/bin/bash

REMOTE="origin";
RBRANCH="$1";

BRANCH=$(git br | grep '^\*' | cut -d' ' -f2);

if [ -z "$RBRANCH" ]; then
        RBRANCH="$BRANCH";
        if [ "$RBRANCH" != "master" -a "$RBRANCH" != "2.0.x" ]; then
                echo "Do you want to push to $RBRANCH?";
                select answer in Yes No; do
                        if [ "$answer" != "Yes" ]; then
                                echo "Aborting push.";
                                exit 1;
                                break;
                        else 
                                break;
                        fi
                done
        fi
fi

if ! git push -n $REMOTE $BRANCH:$RBRANCH >/dev/null 2>&1; then
        echo "Branch is not up to date!";
        exit 1;
fi

LOGS=$(git push -n $REMOTE $BRANCH:$RBRANCH 2>&1 | tail -n 1 | grep -v 
"Everything" | sed -e 's/^ *//' -e 's/ .*//');

if [ -z "$LOGS" ]; then
        echo "Everything up to date";
        exit 0;
fi
echo $LOGS
git log $LOGS;

#Do we want to go ahead?
echo
echo "Do you want to push these commits to $RBRANCH?"
select answer in Yes No; do
        if [ "$answer" != "Yes" ]; then
                exit 0;
                break;
        else 
                break;
        fi
done

COMMITS="";
for i in `git log $LOGS | grep -P '^commit' | cut -d' ' -f2`; do 
        COMMITS="$i
$COMMITS";
done

for i in $COMMITS; do 
        git push $REMOTE $i:$RBRANCH;
done

Reply via email to