A Simple Shell Function to Update Git Branches
A client of mine was having a hard time remembering the project workflow to keep topic branches updated, so I put together this simple shell function as a workflow reference:
function git-sync-master() {
git checkout master &&
git fetch origin &&
git pull origin master &&
git checkout $1 &&
git rebase master
}
As written, that could be added to a ~/.bash_profile
or similar location allowing you to run something like:
$ cd myproject
$ git-sync-master mybranch
Taking this one step further, you can "integrate" this command in to git with the following minor modifications:
$ cat > ~/bin/git-sync-master
git checkout master &&
git fetch origin &&
git pull origin master &&
git checkout $1 &&
git rebase master
^D
$ chmod +x ~/bin/git-sync-master
$ cd myproject
$ git sync-master mybranch
Written by Phil Cohen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#