Last active
January 14, 2018 16:35
-
-
Save jesseskinner/9940594 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# usage: "newgit some/path" | |
newgit() { | |
### SETTINGS ### | |
# this is the root of all your git folders | |
local LOCAL_GIT_ROOT=~/web | |
# this is your ssh [user]@[host] | |
local SSH=user@example.com | |
# this is the folder/path in your ssh user's home directory | |
local SSH_GIT_ROOT=git | |
# make sure there is a path provided, otherwise show the usage | |
if [ $1 ]; then | |
### CREATE GIT SETUP ### | |
# create local git folder | |
cd $LOCAL_GIT_ROOT | |
git init $1 | |
cd $1 | |
# set up a post-commit to auto-push on commit | |
echo "#!/bin/bash" > .git/hooks/post-commit | |
echo "git push origin HEAD" >> .git/hooks/post-commit | |
chmod 755 .git/hooks/post-commit | |
# create remote repository via ssh | |
ssh "$SSH" "git init --bare $SSH_GIT_ROOT/$1" | |
git remote add origin "ssh://$SSH/~/$SSH_GIT_ROOT/$1" | |
# set up empty README file as initial content | |
touch README | |
git add README | |
git commit -m "init" | |
# start off in dev branch | |
git checkout -b dev | |
else | |
echo "Usage: newgit some/path" | |
fi | |
} |
Updated to just call git init instead of doing mkdir, since it'll create the folder for me and any parent folders as necessary.
Updated with condition so it won't run unless there is a path provided.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is my local git setup script, for creating a new SSH remote repository and local folder.