Wednesday, December 10, 2014

Put your existing git repo to amazon EC2 instance


Assumptions:

EC2 Specifications: Ubuntu 14.04
GIT installed,
We have Server details as
    IP Address
    UserName

Steps:

  • Connect to EC2 using ssh connection
ssh <username>@<serverIP>

  • Setup git repo on Amazone EC2 Server: here we are creating bare git reppo, which contents only commits and changes (git details) and not the actual content
mkdir -p project_name/my_project.gitcd project_name/my_project.gitgit init --bare

  • Create post-receive hook: this hook will create actual content of the reppo, at the path you specify as GIT_WORK_TREE
vi hooks/post-receive
And write the following content in the file 
#!/bin/sh
GIT_WORK_TREE=/home/ubuntu/www
export GIT_WORK_TREE
git checkout -f

  • Add remote of EC2 to your local git repo (back to your local terminal)
git remote add production ssh://<username>@<serverIP>:/home/ubuntu/project_name/my_project.git

  • Push your existing repo to that remote
git push production <YOUR_BRANCH>


For more referance:

Special Thanks (for helping me to get understand)
    • Rakshit Menpara 


No comments:

Post a Comment