简体   繁体   中英

One git command to create new local branch, push to origin, track origin

A common part of my workflow is:

git checkout -b new_branch origin/master
git push origin new_branch
git branch --set-upstream-to origin/new_branch

Is there a way this could be boiled down to one command? I'd like to be able to set up an alias so that this can be done with something quick to type such as:

gitnew new_branch parent_branch

A bash solution is acceptable, but would be neat if it were pure git.

Is there a way this could be boiled down to one command?

Yep, add && between each command

git checkout -b new_branch origin/master &&
git push origin new_branch &&
git branch --set-upstream-to origin/new_branch

On single line


git alias

You can use git alias to define those set of command as well.

git config --global alias.newb "!f(){ git checkout -b $1 origin/$2 && git push origin &1 && git branch --set-upstream-to origin/$1 };f"

$1 = name of new branch
$2 = name of parent branch

How to use:

git newb new_branch_name master

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM