Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setting up a remote Git in AWS EC2

AWS Remote Git Setup

Get a local git repo up on an EC2 Instance.

Add youself to SSH Authentication:

Add yourself to the ssh auth agent, if you haven't already.

ssh-add path/to/your/EC2.pem

Set up destination directory:

SSH into the remote directory, and create a barebones remote repo directory.

ssh ec2Username@long-crazy-amazon-ip.com 
mkdir repo-name.git && cd repo-name.git 
git init --bare

Set up your local to push to our new remote:

cd repo-name 
git init git add . 
git commit -m "Initial git commit message" 
git remote add origin ec2Username@long-crazy-amazon-ip.com:/path/to/your/repo-name.git 
git config --global remote.origin.receivepack "git receive-pack" # needed for aws ec2 stuff.
git push origin master

Cloning repository

The origin url can be used for cloning too.

git clone ec2Username@long-crazy-amazon-ip.com:/path/to/your/repo-name.git 

(This guide was lifted from here, then modified slightly.)

@buckeyja

This comment has been minimized.

Copy link

commented Dec 21, 2018

Thanks matthewoden,

After following your instructions and running $git push origin master everything seems to work but the files don't show up in the remote repository when I run $ls.

@mritunjay10

This comment has been minimized.

Copy link

commented Feb 7, 2019

It worked successfully but after pushing my website how can I view it?

@akun1

This comment has been minimized.

Copy link

commented Apr 12, 2019

Great post, thanks!!

So I had the same issue as @buckeyja, but I found out why. Basically, if you go to your remote machine, you'll see the BARE git repo. A bare repo doesn't have a "working tree" or something which means all you can do is pull from it. So, in order to see/edit your files on your remote machine, just pull from there.

Example:
Get on your remote machine in the same directory as your .git file and run:
git clone [-b branchName] git@path_to_your_git_repository

Here's a link to the SO answer I found all this out from, give the answer an upvote!! https://stackoverflow.com/questions/1456923/why-am-i-getting-the-message-fatal-this-operation-must-be-run-in-a-work-tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.