git—save everyting to master with message shortcut

May 13, 2020 ≈ 32 seconds

For saving everything to master with a message from whatever branch I work in (and delete it after), I like to use this shortcut.


saveas() # save to master as
{
    if [ -z "$1" ]; then                           # Is parameter #1 zero length?
        echo "you need to specify parameters..."
        return 0
    fi

    current_branch=$(git symbolic-ref --short HEAD)

    # save everything with message from parameters 
    git add .
    git commit -m "$1"

    # if we are on master, return
    if [ "$current_branch" = "master" ]; then
        return 0
    fi

    # if not on master, merge current branch and delete it
    git checkout master
    git merge $current_branch
    git branch -d $current_branch
}

#git

Subscribe to our newsletter

If you provide url of your website, we send you free design concept of one element (by our choice)

Subscribing to our newsletter, you comply with subscription terms and Privacy Policy