Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
}
@jesseskinner
Copy link
Author

jesseskinner commented Apr 2, 2014

This is my local git setup script, for creating a new SSH remote repository and local folder.

@jesseskinner
Copy link
Author

jesseskinner commented Apr 2, 2014

Updated to just call git init instead of doing mkdir, since it'll create the folder for me and any parent folders as necessary.

@jesseskinner
Copy link
Author

jesseskinner commented May 22, 2014

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