g7bzkg
Last Updated: February 25, 2016
·
1.854K
· blainesch

Git Push/Pull/Rebase in a single command

tldr - Stashes changes, does a fresh pull, does a push, then unstashes or alerts you of a rebase conflict.

Do your pushes frequently get rejected due to somebody else pushing before you? It can be very frustrating, so before you go adopting something useful like git flow consider this shell alias/function.

function gp() {
    echo 'Starting Push/Pull\n'

    local staged=false
    if ! git stash | grep '^No local changes to save$'
    then
        staged=true
        echo 'Stashing current changes\n'
    fi

    echo 'Pushing\n'
    if git pull --rebase $@ && git push
    then
        if $staged
        then
            echo 'Unstaging\n'
            git stash pop
        fi
        echo 'Complete\n'
    else
        echo 'Rebase conflict.'
        if $staged
        then
            echo 'WARNING: Be sure to run "git stash pop" when rebase completes.\n'
        fi
    fi
}

I created and modified function this for months while our workflow including us all pushing to dev branches. We've long since lost this workflow (thankfully) but it's still useful when I work from multiple computers. I hope it can help somebody!

1 Response
Add your response

6969

Hi, git-up just does the job (and much more, when you hunt the doc), colorfully, and is well maintained. I use it with these git aliases:

pushall = !git push --all && git push --tags
upa = !git up && git push --all && git push --tags

Regards,

over 1 year ago ·