Last Updated: February 25, 2016
·
1.95K
· jkirchartz

Quicker Git Add Commit Push

Add this to your .bash_profile:

function gcp () {
    if [ -z "$1" ]
    then
        read -p "Commit Message:" MSG
    else
        MSG="$1"
    fi
    git add .
    git commit -am "$MSG"
    git push
}

now whenever you want to commit and push just execute

gcp "This is the comment"

if you don't supply a commit message it will prompt you for one.

If you'd rather git open your default editor to comment, use this:

function gcp () {
    git add .
    git commit -a
    git push
}

but you can get the best of both worlds, one-liner messages, OR editor messages with something like this:

function gcp() {
    git add .
    if [ -z "$1" ]
    then
        git commit -a
    else
        git commit -am "$1"
    fi
    git push
}