Setting up a Git repository on an Amazon EC2 instance

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.

ssh-add path/to/privateEC2key.pem

Now you can go ahead and create the git repository on the EC2 instance.

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 
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

That’s it! Much thanks to Jamie Hill @ for his tutorial. Check it out for a slick tip on tracking the remote repository.


2 Comments on “Setting up a Git repository on an Amazon EC2 instance”

  1. Josh says:

    getting a “does not appear to be a git repository” on push check the ec2 and the git repo is there and I followed you directions to the t

    • Tony Ghita says:

      Hmm… keep in mind that will look for a git repository in a folder of the home directory of “username” called “the_project.git”.

      If you’ve got everything set up correctly, then what worked for me was adding that configuration line, “git config –global remote.origin.receivepack “git receive-pack””.

      Other than that, dunno buddy.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s