From 8f75b764caa87cece86f65b717c92353a0f27e0c Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Fri, 20 Jan 2017 09:46:26 -0600 Subject: [PATCH] Add gsync function for upstream Git branch syncer. --- .bash_profile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.bash_profile b/.bash_profile index abe661e..d824349 100644 --- a/.bash_profile +++ b/.bash_profile @@ -58,6 +58,25 @@ alias gl='git log --graph --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset % alias gsd='git svn dcommit' alias gsfr='git svn fetch && git svn rebase' +# Git upstream branch syncer. +# Usage: gsync master (checks out master, pull upstream, push origin). +function gsync() { + if [[ ! "$1" ]] ; then + echo "You must supply a branch." + return 0 + fi + + BRANCHES=$(git branch --list $1) + if [ ! "$BRANCHES" ] ; then + echo "Branch $1 does not exist." + return 0 + fi + + git checkout "$1" && \ + git pull upstream "$1" && \ + git push origin "$1" +} + # Turn on Git autocomplete. brew_prefix=`brew --prefix` if [ -f $brew_prefix/etc/bash_completion ]; then