Skip to content

Instantly share code, notes, and snippets.

@SteveBenner
Last active November 30, 2016 06:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveBenner/de003aa46811ed6c6f0f to your computer and use it in GitHub Desktop.
Save SteveBenner/de003aa46811ed6c6f0f to your computer and use it in GitHub Desktop.
Bash functions for managing Git
#
# FUNCTIONS
#
# Test the first argument of a command for a git host identifier (aliases configured in ssh-config)
is_git_host() {
case "$1" in
'gh') host='github-personal'
user='SteveBenner'
true ;;
'bb') host='bitbucket'
user='SteveBenner09'
true ;;
'xf') host='github-work'
user='xFactorApplications'
true ;;
*) echo 'Usage: clone [host] [repository-name]'
echo "where <host> is one of:"
echo ' gh: Personal GitHub account'
echo ' xf: X-Factor Applications GitHub account'
echo ' bb: personal BitBucket account'
false ;;
esac
}
# Clone a git repo using hostname aliases resolved via SSH configuration
clone() { if is_git_host $1 ; then `git clone git@${host}:${user}/${2}.git` ; fi }
# Initialize a new local git repository, setting the remote using given alias
ginit() {
if is_git_host $1 ; then
git init
`git remote add origin git@${host}:${user}/${2:-$(basename $(pwd))}.git`
echo "# Coming soon..." >> README.md
cp -n ~/.gitignore_global .gitignore
git add -A
git commit -m "Initial commit."
git push -u origin master
`git config core.filemode false`
fi
}
@SteveBenner
Copy link
Author

See my related blog post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment