Setting up a Git repository on an Amazon EC2 instancePosted: May 4, 2011
Put a git repository on the cloud… all the cool kids are doing it, and you can too! Here’s how:
First and foremost, you need to add your EC2 identity to the ssh authentication agent. This prevents problems with git later, namely getting the error “Permission denied (publickey).” when trying to do a git push to the EC2 repository.
Now you can go ahead and create the git repository on the EC2 instance.
ssh firstname.lastname@example.org mkdir the_project.git cd the_project.git git init --bare
So not much going on here, all we do is create an empty repository and then leave. Now, on the local machine, you do something like the following:
cd the_project git init git add . git commit -m "Initial git commit message" git remote add origin email@example.com:the_project.git git config --global remote.origin.receivepack "git receive-pack" git push origin master
The ‘git config’ command is a fix that I found necessary to be able to push to the EC2 repository. I was getting errors that looked like “git: ‘the_project.git’ is not a git command. See ‘git –help’.”, and this fixed that problem. You can read more about this at StackOverflow. At this point you should have successfully created an EC2 git repository! Congrats! Team members can now clone the remote repository like so:
git clone firstname.lastname@example.org:the_project.git
That’s it! Much thanks to Jamie Hill @ theLucid.com for his tutorial. Check it out for a slick tip on tracking the remote repository.