Skip to content

Instantly share code, notes, and snippets.

@mmastoras
Created March 14, 2012 19:44
Show Gist options
  • Save mmastoras/2038948 to your computer and use it in GitHub Desktop.
Save mmastoras/2038948 to your computer and use it in GitHub Desktop.
promote local topic branch to remote tracking branch of same name
#!/bin/sh
#
# Promotes a local topic branch to a remote tracking branch of the same name,
# by pushing and then setting up the git config
#
# Thanks to ENTP:
# http://hoth.entp.com/2008/11/10/improving-my-git-workflow
curr_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')
remote_branch=$(git branch -r | grep "origin/${curr_branch}")
[ -z "${remote_branch}" ] && ( git push origin "${curr_branch}" )
origin=$(git config --get "branch.${curr_branch}.remote")
[ -z "${origin}" ] && ( git config --add "branch.${curr_branch}.remote" origin )
merge=$(git config --get "branch.${curr_branch}.merge")
[ -z "${merge}" ] && ( git config --add "branch.${curr_branch}.merge" "refs/head
s/${curr_branch}" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment