1. Install git on your EC2 instance
> ssh -i amazonkey.pem ec2-user@example.amazonaws.com > sudo yum install gitamazonkey.pem should be the identity file provided when you setup your amazon EC2 instance.
example.amazonaws.com will be your EC2 instance hostname, something like ec2-111-111-111-111.ap-northeast-1.compute.amazonaws.com
2. Setup a git repository on your EC2 instance
From the directory /home/ec2-user> mkdir test.git > cd test.git > git init --bare
3. Configure ssh so git can access your amazonkey.pem
On your local machine edit ~/.ssh/config and add the following :Host amazon Hostname example.amazonaws.com User ec2-user IdentityFile amazonkey.pemReplace example.amazonaws.com with your EC2 instance name and replace amazonkey.pem with the location and name of your key file from amazon.
You can test it is working by sshing onto the instance with the command
> ssh amazonIt should successfully log you in to your EC2 instance at this point.
4. Create a local git repository and push it to your remote repository.
One the local machine> mkdir test > cd test > git init > echo "here is some text">text.txtThis creates a file called test.txt with some text in it so you have something to commit.
> git add * > git commit -m "initial commit" > git remote add origin amazon:/home/ec2-user/test.git > git push -u origin masterAt this point you should see some messages about git counting, compressing and writing objects. If there are any fatal errors at this point check that the git remote add origin path after amazon: matches where you created the empty git repository in step 2.
5. Checkout the changes to make sure they worked
On your local machine in an empty directory.> git clone amazon:/home/ec2-user/test.git > cd test > cat test.txtThis should display the text you entered into the test.txt file in step 4 that has gone via the EC2 instance and git all the way back to your local machine.
References
http://stackoverflow.com/questions/4632749/how-to-push-to-git-on-ec2
http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/
http://dracoblue.net/dev/custom-identity-file-idrsapub-with-git-client/193/