7 Kudos

Quick Remote Git Repository Creation Script

If you are using Git for your source code management, GitHub is an awesome tool. It especially shines for public projects where you freely allow others to fork your code and possibly pull patches back in.

Sometimes I'm just working on a project that I would prefer to keep in a private repository. GitHub provides paying accounts with such an option. However, I already have hosting accounts that are terribly underused. Here is a little script I use to create a remote git repository on one of my VPS accounts that I can then pull from and push to.

Prerequisites
A hosting account which you can ssh / scp into.

The Script

$ vim new_repo


#! /bin/sh

mkdir $1
cd $1
git init-db
touch README
git add .
git commit -m "Initial Repository Creation"
cd ..
git clone --bare $1/.git $1.git
scp -r $1.git user@XXX.XXX.XXX.XXX:/home/user/repos/
rm -rf $1.git
rm -rf $1
git clone user@XXX.XXX.XXX.XXX:/home/user/repos/$1.git

exit 0


Of course, you will need to change "user" with an actual user on your hosting account, adjust XXX.XXX.XXX.XXX to point to your accounts IP address, and replace /home/user/repos/ with whatever path you wish to contain your Git repositories.

Once that is done, provide executable permissions.

$ chmod +x new_repo

That's it. Now if you execute:

$ ./new_repo testing

You will end up with /home/user/repos/testing.git on your remote host, and ./testing locally. From ./testing you can git push to send commits to the remote repository, and git pull to retrieve from the remote repository.

If you see room for improvement, I'm sure there is some, please leave a comment with your revision!
Sponsors
Sponsors
About the Author

7 Kudos
Top Entertainment Articles
Lindsay Lohan's Assistant Worries Lindsay Will Kill Herself
In yet another recording released by Lindsay's dad Michael, her assistant Jenni Muro says, "I am trying to save your daughter's life every day." Wait, Lindsay Lohan has an assistant?
Twilight’s Christian Serratos Gets Naked For PETA
Serratos poses naked for the 'I'd Rather Go Naked Than Wear Fur' campaign.
100 Best Bikini Bodies
Click here for the best way to spend 10 minutes.
More From Zimbio
Copyright © 2009 - Zimbio, Inc. Some rights reserved.