Last active
November 30, 2016 06:02
-
-
Save SteveBenner/de003aa46811ed6c6f0f to your computer and use it in GitHub Desktop.
Bash functions for managing Git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my related blog post