> For the complete documentation index, see [llms.txt](https://tkssharma-devops.gitbook.io/devops-training/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tkssharma-devops.gitbook.io/devops-training/version-control/untitled/setting-up-remote-repo.md).

# Setting up Remote Repo

setting up git remote Repo

Sign in if you have account, if not make one

![](https://cdn-images-1.medium.com/max/1600/1*tuWALeUhgqzoNb2ecO1jVw.png)

3\. Click on EC2

![](https://cdn-images-1.medium.com/max/1600/1*3t-6otmkY6e_jyrpxbJZmQ.png)

4\. Click on Launch Instance

![](https://cdn-images-1.medium.com/max/1600/1*vMyLeGiv7V3fXkaULSQpug.png)

5\. Select Ubuntu

![](https://cdn-images-1.medium.com/max/1600/1*PpbjIN7Waqhyyn9rYUsI3Q.png)

6\. Select Free Tier t2 micro

![](https://cdn-images-1.medium.com/max/1600/1*rdiFcCwtAwvt5OuxeQCIHQ.png)

7\. Configure Instance Details

![](https://cdn-images-1.medium.com/max/1600/1*DSlFIFLh5r6nJ_Pm9vcgRQ.png)

8\. Add Storage if you need it

![](https://cdn-images-1.medium.com/max/1600/1*kTG4fHIo1sn8vubNB4RCYw.png)

9\. Add a tag if you want to

![](https://cdn-images-1.medium.com/max/1600/1*gg37LcodstDsX9WlBYCQjw.png)

10\. Launch your instance

![](https://cdn-images-1.medium.com/max/1600/1*Jqv6y5oqxwBTSUSuNPfBmA.png)

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

![](https://cdn-images-1.medium.com/max/1600/1*-FX9vQNrEE7K6pOOeKQRMA.png)

12\. Launch the instance. Done!, Now we can ssh to this instance&#x20;

```
       __| __|_  )       _| (   / 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:<br>

**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&#x20;

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

![](https://3776180966-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgLv25e2BrxRC5m6flh%2F-LhoB2hDjhV3vpgsYfLD%2F-LhoFqcKjlVWKwWcO562%2Fhooks.jpeg?alt=media\&token=71520e36-f593-4309-819d-3a43618d72c2)

![](https://3776180966-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgLv25e2BrxRC5m6flh%2F-LhoB2hDjhV3vpgsYfLD%2F-LhoHS1JABbaSNjOAmsJ%2F01.jpeg?alt=media\&token=ccfdac0e-9e13-42fc-8f7a-37c6b71e8b81)

\ <br>
