Creating a remote GIT repository
Clean, readable code is one of my highest goals when writing code. I’m always thinking about the next guy, even when the next guy is just me, several months from now. Nothing is worse than going into spagetti code and not knowing what the heck is going on. Because of this, I like to refactor my code A LOT. When you are using source control, you never get yourself into situations that you can’t get out of. It’s also nice to go back and see how the code has evolved over time, to see why certain files were changed. Because of all these benefits, I use source control even on my own tiny projects where I’m the only developer.
I have used visual source safe when I first got started and like all vss users, quickly moved away from it. I’ve spent most of my career using perforce for work. I tried out Subversion a long time ago, but I got tired of my database getting corrupted and having to drop to the command line to repair it. I used a very early version of subversion and I hear that it is MUCH better now. Anyway, I used perforce for my personal stuff because the first two clients were free. Since I’m learning everything else, why not throw in GIT too. It’s gotten a lot of press so I want to see what the fuss is all about. Here is how I installed my first GIT repository on my ubuntu server.
ssh to the remote box and type the following commands:
sudo apt-get install git-core sudo mkdir /var/git sudo mkdir /var/git/snowcaptech.git sudo chown jason /var/git/snowcaptech.git sudo chmod 775 /var/git/snowcaptech.git cd /var/git/snowcaptech.git git init --bare --shared=group
What we are doing is creating an empty directory in the /var/git folder where I like to keep all my git repositories. We are then changing the owner to me and setting permissions for me to write and everyone else to be able to read. The git init –bare creates a repository without a working copy.
then to add a project from your local client to the remote repository, you would first tell GIT about your project by going to the directory of your project and from a command prompt typing:
git init git add . git commit -m "initial checkin"
This initializes your repository and commits it to your local GIT repository. This is all you need to do to have a working source control system for just yourself.
I like to make my source available on a server so I can access it from anywhere on the planet. I never need to do this, but it is cool to be able to do this. In order to “push” your local GIT repository to the remote repository, you have to tell your local repository about the remote. Sorry if that was confusing. Read it a few times.
git remote add origin jason@dev.snowtech.com:/var/git/snowcaptech.git git push origin master
As long as your settings are all correct, your repository should now be at the remote repository.