Last Updated: February 25, 2016
·
644
· roparz

Git: quick fix in a new branch from master

fix = "!f() { msg=$1; branch=${msg// /_}; git checkout -b ${branch}; git add --all; git commit -m \"${msg}\"; git push --set-upstream origin ${branch}; git checkout master; }; f"

Usage:

git fix "this is a little fix"

Explanation:

f() { 
    msg=$1; # get first argument
    branch=${msg// /_}; # normalize msg to use it as branch name
    git checkout -b ${branch}; # checkout branch
    git add --all; # add all file in staging area
    git commit -m \"${msg}\"; # commit with message
    git push --set-upstream origin ${branch}; # push to origin
    git checkout master; # go back to master
};

Tada!