Skip to content

Instantly share code, notes, and snippets.

@matthewoden
Created May 22, 2016 17:48
Show Gist options
  • Save matthewoden/b29353e266c554e04be8ea2058bcc2a0 to your computer and use it in GitHub Desktop.
Save matthewoden/b29353e266c554e04be8ea2058bcc2a0 to your computer and use it in GitHub Desktop.
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 [email protected] 
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 [email protected]:/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 [email protected]:/path/to/your/repo-name.git 

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

@buckeyja
Copy link

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
Copy link

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

@akun1
Copy link

akun1 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