Part 1: Connect to your Amazon EC2 Ubuntu instance and run the following commands to install git
1. Navigate to the home directory:
cd ~
2. Use apt-get to install git-core:
sudo apt-get -y install git-core
3. Set up the git user:
git config --global user.name "John Smith"
git config --global user.email john.smith@email.com
4. Make a directory for the git repository, navigate to it, and initialise it with --bare
mkdir test_repo.git
cd test_repo.git
git init --bare
Part 2: Clone your git repository locally to initialise it
1. Open Putty to SSH to your EC2 instance and "Allow Agent Forwarding" in the settings for the connection so that you can authenticate through a second ssh session (this is to perform the clone which will create a local repository on the EC2 machine). See image below (Connection --> SSH --> Auth)
2. Make a new directory for the git clone
cd ~
mkdir test_clone
cd test_clone
3. Initialise the git repository for the clone folder
git init
git remote add origin ssh://ubuntu@localhost/test_repo.git
Part 3: Setup the connection from SourceTree on your Windows computer
1. Add your private key to the Pageant tool in the task bar (it is installed with SourceTree)
2. In Source Tree click 'Clone/New'
3. In the Source Path/URL enter a connection formatted similar to below:
ec2username@ec2-ipaddress.location.compute.amazonaws.com:~/test_repo.git
e.g. ubuntu@ec2-12-345-678-90.ap-southeast-2.compute.amazonaws.com:~/test_repo.git
If all ok, the 'Repository Type' should say "This is a git repository". If not, try going to your test_repo.git folder and type "git status" to see if the repository is having any problems.
(i.e. type
cd ~/test_repo.git
git status)
4. Set the Destination Path to a folder on your local computer where you want your local git repository to be located.
5. Click "Clone" when done.
Note: To be updated in future with more screenshots & better descriptions.
Useful Links:
http://thealarmclocksixam.wordpress.com/2013/01/06/git-repo-tutoria/
https://www.atlassian.com/software/sourcetree/
https://bitbucket.org/ (free private repo for up to 5 users - alternative to github which is only free if your repo is public). Not required for git, only if you want a third party to also host your repo.
http://git-scm.com/documentation - Git Documentation