Skip to content

Instantly share code, notes, and snippets.

@jesseskinner
Last active January 14, 2018 16:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jesseskinner/9940594 to your computer and use it in GitHub Desktop.
Save jesseskinner/9940594 to your computer and use it in GitHub Desktop.
#!/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

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

@jesseskinner
Copy link
Author

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

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