6. Change Git Remote URL in Local Machine Repository

1. In Local Machine, backup your particular git repository config file:

cd /.git
cp config config_bk

2. Edit git repository config file:

nano config

[remote “origin”]

fetch = +refs/heads/*:refs/remotes/origin/*

url = git@git:<repositoryDirectory>.git

3. Try if it is works. It will returns “Everything is up-to-date” message if connection is successfully:

git pull --rebase

5. Configure new user to access to your own EC2 Git Server

1. Make a .ssh directory in your local machine home directory and Copy your EC2 pem file into your home directory:

cd
mkdir .ssh
cd .ssh
cp /path/pemfile.pem /home/username/.ssh

2. Get the EC2 server instance login and create a SSH config file to access to EC2 server instance:
Create a new file “~/.ssh/config” which contains your Amazon EC2 hostname, user and PEM key location.

nano config

Host git
Hostname EC2PublicDNS
User ubuntu
IdentityFile /home/username/.ssh/pemfile.pem

With this configuration, we can login into EC2 server instance with:

ssh git
exit

3. Back to local machine, generate and copy your SSH public key into EC2 server instance:

ssh-keygen -t rsa
cp ~/.ssh/id_rsa.pub /tmp/username.pub
rsync -avr /tmp/username.pub -e "ssh -i /home/username/.ssh/pemfile.pem" ubuntu@EC2PublicDNS:/tmp/username.pub

4. Login into EC2 server instance and Change username.pub file permission:

ssh git
chmod 766 /tmp/username.pub

5. Grant our local machine access into EC2 server instance:

sudo su - git
gl-setup /tmp/username.pub

6. Back to your local machine. Try Clone test1.git repo:

eval `ssh-agent`
ssh-add
cd
git clone git@git:test1.git

4. Migrating Git Repositories from your old Git Server to Amazon EC2 New Git Server

1. Connect to your old Git Server through a FTP software. Ex. Filezilla.

2. In Filezilla, Go to your Git repository path.

3. Download all repository directories into your local machine.

4. Connect to EC2 Git Server Instance through Filezilla.

5. Copy repository directories from your local machine into EC2 Server /home/ubuntu directory.

6. Open Terminal, ssh to EC2 Git Server Instance:

ssh git

7. Change repository directory user and group owner to git:

sudo chown -R git:git DirectoryName 

8. Copy repository directories from ubuntu directory to git repository directory with retaining the permission:

sudo cp -rp DirectoryName /home/git/repositories/

3. Setup GitWeb in Amazon EC2

1. SSH to EC2 Git Server instance:

ssh git

2.  Install Apache:

sudo apt-get install apache2

3. Install GitWeb:

 sudo apt-get install highlight gitweb

4. Edit GitWeb config file:

sudo nano /etc/gitweb.conf

$projectroot = “/home/git/repositories”;
# Add Highlighting at the end
$feature{‘highlight’}{‘default’} = [1];

5. Grant Permission for Git Directories to be accessed by GitWeb:

sudo usermod -a -G git www-data<br />
sudo chmod g+r /home/git/projects.list<br />
sudo chmod -R g+rx /home/git/repositories

6. Restart Apache:

sudo service apache2 restart

7. Go to your browser. Test GitWeb by input the URL:
http://YourEC2PublicDNS/gitweb

2. Create New Git Repository in Amazon EC2

1. From Local Machine, ssh to EC2 Git instance server by:

ssh git

2. Create a test repository in EC2 Git instance server:

sudo su - git
cd repositories
mkdir test1.git
cd test1.git
git init --bare
nano description

3. Back to local machine. Go to gitolite-admin repository and Edit gitolite.conf to have the new added repository.

cd
cd ~/gitolite-admin/conf
nano gitolite.conf

Add following lines:

repo    test1
RW+     =   @all

4. Push gitolite.conf file to EC2 Git instance server:

git add conf/gitolite.conf
git commit -e
git push

5. Push local test1 directory into EC2 Git instance server:

cd
cd test1
git init
git add *
git commit -m "Initial Commit"
git remote add origin git@git:test1.git
git push -u origin master

6. Try Clone test1 repository into your local machine /tmp directory.

cd /tmp
git clone git@git:test1.git 

1. Setup Git Server in Amazon EC2

1. Setup a Ubuntu EC2 server instance in https://console.aws.amazon.com/ec2.
In my case, I’ve setup Ubuntu 12.04 64Bit Server with m1.small instance type.

2. Make a .ssh directory in your local machine home directory and Copy your EC2 pem file into your home directory:

cd
mkdir .ssh
cd .ssh
cp /path/pemfile.pem /home/username/.ssh

3. Get the EC2 server instance login and create a SSH config file to access to EC2 instance:

Create a new file “~/.ssh/config” which contains your Amazon EC2 hostname, user and PEM key location.

nano config

Host git
Hostname EC2PublicDNS
User ubuntu
IdentityFile /home/username/.ssh/pemfile.pem

With this configuration, we can login into EC2 server instance with:

ssh git
exit

4. Back to local machine, generate and copy your SSH public key into EC2 server instance:

ssh-keygen -t rsa
cp ~/.ssh/id_rsa.pub /tmp/username.pub
rsync -avr /tmp/username.pub -e "ssh -i /home/username/.ssh/pemfile.pem" ubuntu@EC2PublicDNS:/tmp/username.pub

5. Login into EC2 instance and Change username.pub file permission:

ssh git
chmod 766 /tmp/username.pub

6. Install gitolite in EC2 server instance:

sudo apt-get install git gitolite git-daemon-run

Create new git account for gitolite and grant our local machine access into EC2 instance:

sudo adduser --system --shell /bin/bash --gecos 'git version control' --group --disabled-password --home /home/git git
sudo su - git
cd /home/git
echo "PATH=$HOME/bin:$PATH" > .bashrc
gl-setup /tmp/username.pub

Change umask setting in /home/git/gitolite.rc
$REPO_UMASK = 0027;

7. Back to your local machine. Try Clone gitolite-admin repo:

eval `ssh-agent`
ssh-add
cd
git clone git@git:gitolite-admin.git