Skip to content

Instantly share code, notes, and snippets.

@ericboehs
Created July 14, 2009 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericboehs/146661 to your computer and use it in GitHub Desktop.
Save ericboehs/146661 to your computer and use it in GitHub Desktop.
Init's a git repo on a remote git server and then pushes the current directory to it (not for use w/ github)
#!/bin/bash
# rgi by Eric Boehs
# I like to put this in my ~/bin (which I put in my path) as rgi (remote git initialize)
# Specify your remote user@server here
GIT_DOMAIN=user@example.com;
# ======================
# = END OF USER CONFIG =
# ======================
# Use the current directory for the $dir variable
dir=$(basename $(pwd));
# Create the remote directory and do a bare init on it
ssh $GIT_DOMAIN 'mkdir -p ~/git/'$dir'.git && cd ~/git/'$dir'.git && git --bare init';
# Do stuff to the local directory
git init;
# Add the remote repo as origin and also set it to track master (so you don't have to specify anything after your git push command)
git remote add -t master origin ssh://$GIT_DOMAIN/~/git/$dir.git;
# This is to hide Mac OS X's nasty .DS_Store file
echo ".DS_Store" >> .gitignore;
# And the rest should be pretty familiar
git add .;
git commit -m 'Created new repo';
git push origin master;
echo "Your new git repo '$dir' is ready and initialized at $GIT_DOMAIN/~/git/$dir.git";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment