Setting up Remote Repo

setting up git remote Repo

Sign in if you have account, if not make one

3. Click on EC2

4. Click on Launch Instance

5. Select Ubuntu

6. Select Free Tier t2 micro

7. Configure Instance Details

8. Add Storage if you need it

9. Add a tag if you want to

10. Launch your instance

11. Create a key pair and make sure to save it somewhere safe. You won’t be able to replace it.

12. Launch the instance. Done!, Now we can ssh to this instance

       __| __|_  )       _| (   / Amazon Linux AMI      ___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2016.09-release-notes/
chmod 400 key.pem
ssh -i key.pem ec2-user@x.x.x.x // get piblic ip of system 
# exit from server now we are able to ssh to remote server 
# now add local public key to server  [Important step]
cat ~/.ssh/id_rsa.pub | ssh -i  key.pem  ec2-user@x.x.x.x "cat>> .ssh/authorized_keys"

ssh -i key.pem ec2-user@x.x.x.x
# enter to the remote system console 
mkdir app.git
cd app.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:

Access remote repo :

.ssh >  git clone ssh://ec2-user@x.x.x.x/home/ec2-user/app.git
Cloning into 'myproject'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
 git:(master) git remote -v
origin ssh://ec2-user@x.x.x.x/home/ec2-user/app.git (fetch)
origin ssh://ec2-user@x.x.x.x/home/ec2-user/app.git (push)

Create POST Receive Hook

Crate POST receive push Hook
chmod +x hooks/post-receive
chmod +x hooks/post-receive
GIT_WORK_TREE=/home/ec2-user/myproject
export GIT_WORK_TREE
git checkout -f
cd /home/ec2-user/myproject
sudo npm install
forever start app.js

Here we go.. we are able to setup bare repo on server and accessing it from application containers.

Last updated