Skip to content

Instantly share code, notes, and snippets.

@washingtontimes
Created March 16, 2010 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save washingtontimes/333816 to your computer and use it in GitHub Desktop.
Save washingtontimes/333816 to your computer and use it in GitHub Desktop.
A git command to push a local branch to the origin repository.
#!/bin/bash
function push_branch () {
HAS_REMOTE=`git show-ref remotes/origin/$1`
HAS_LOCAL=`git show-ref heads/$1`
if [[ $HAS_REMOTE ]]; then
echo "The remote repository already has a branch named $1"
exit
fi
if [[ $HAS_LOCAL == '' ]]; then
echo "There isn't a local branch named $1"
exit
fi
`git push origin $1`
`git config branch.$1.merge refs/heads/$1`
`git config branch.$1.remote origin`
}
push_branch $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment