I have this new server that I wanted to use like the services offered by Paas's. After some disappointments with OpenShift and Appfog, I am now using Heroku. And I really
So, until I had to install my own Git server, I never made the difference between the bare repository and the working tree.
Just to make things clear, the bare repo does not contain files, it's just the information about who did what on which file. It's the center/server of your git network. More details here
All the files you have on your repo are a working tree. You can't push to a working tree.
But if you can easily find free server services (Assembla, Bitbucket), it's not a deploy option like in Heroku.
If you are working on a web project, you would like to check the result "live" without having to update it manually.
This is what I did :
1. I installed git on the server
(yum or apt-get or ...) install git-core
2. I created a git user
adduser gitIt will set the new user with no password or '!!'. It may cause problems, so to be sure you can unlock the user
passwd -u git3. I had to register my SSH key (switching to 'git' user is really important)
su - git4. I did the work tree in a web-browser-accessible folder (public_html, www ...) and put a test file to avoid any bug related to cloning an empty repo
cd
mkdir .ssh
ssh-keygen -q -t rsa -N 'pass' -f ~/.ssh/id_rsa
ssh-add
# on CentOS you may need to 'exec ssh-agent bash' to avoid the 'Could not open a connection to your authentication agent.'
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
git init deploy5. Now the bare repo. You should put in your /home/git folder
cd deploy
touch test
git add .
git commit -m 'first'
git clone --bare /home/user/www/deploy deploy.git6. To clone it on my PC, I append my own SSH public key to .ssh/authorized_keys ...
#On the serverYou can also copy the content of your id_rsa.pub and paste with
cat /tmp/id_rsa.pub >> .ssh/authorized_keys
nano authorized_keys7. ... and cloned the repo on my machine
git clone git@myserver:/home/git/test.gitIf you change your code and Push it, it will work but you won't change the deploy folder
8. I had a hook to the bare repo to tell update the live version
cd /home/git/deploy.git/hooks
touch post-receive
nano post-receive
Paste
#!/bin/sh
GIT_WORK_TREE=/home/user/public_html/deploy/ git checkout -f
chmod +x post-receive9. Done! You can push and it will appear on the web folder