My working environment is as follows:
– I work mostly all time on laptop with Windows 7 because I work on projects in both .NET and LAMP.
– I have a virtual machine with Ubuntu server (using VMWare) to test LAMP projects in Linux enviroment.
– Amazon EC2 instance with Ubuntu for testing my sites in the Internet.
– working copies of sites on my local PC;
– two repositories on the server: hub and prime;
– all working repositories work with a hub-repository;
– Live sites are run from prime-repository;
– Changes made to projects locally in working copies are pushed to the hub-repository. Changes are automatically aplplied from hub-repository to prime-repository where live sites are.
– Changes can be also pushed to the prime-repository. In this case the changes are automatically applied to the hub-repository. So working copies of project continue to work with the last version.
This solution has the following advantages:
– I can test my changes immediately in the Internet after I push to the remote hub-repository.
– Changes to the live copy of site do not break the system.
Below is a step-by-step description how to setup this system.
First read my post how to install Git on Windows and Ubuntu.
We need two repositories for a hub and prime:
– /var/www/site1 – prime-repository, live version of site,
– /home/git/repos/site1_hub.git – hub-repository, (bare repository).
Git hub-repositories will be at /home/git/repos.
We create a git user and add users to the git group.
Setup permissions for git
sudo useradd git
sudo usermod -a -G git myuser
Make the git directory readable and writeable by the git group:
sudo chmod -R g+rwX /home/git
Make all files and directories created under
/home/git to retain the git group:
sudo chmod g+s /home/git
Create the folder for repositories:
sudo chown git /home/git/repos
sudo chgrp git /home/git/repos
git add .
git commit -m "first init"
git --bare init
You may create a hub-repository somewhere outside www-folder.
Add the hub-repository as a remote repo for the prime-repository and pull changes from the prime to the hub.
git remote add hub /home/git/repos/site1_hub.git
git push hub master
Setup hooks to synchronize repositories
post-update hook in the hub-repository
Edit or create the file /home/git/repos/site1_hub.git/hooks/post-update
echo "**** get changes for the Prime [Hub's post-update hook]"
cd /var/www/site1 || exit
git pull hub master
Set the permissions:
chmod +x /home/git/repos/site1_hub.git/hooks/post-update
post-commit hook in the prime-repository
Edit or create the file /var/www/site1/.git/hooks/post-commit
echo "**** pushing changes to Hub [Prime's post-commit hook]"
git push hub
permissions on .git directory
deny access to .git directory. Create .htaccess file inside .git directory:
RewriteRule \.git - [F,L]
* Setting up Rails, MySQL, PHP, Apache, and Git on EC2 – http://codelikezell.com/setting-up-rails-mysql-php-apache-and-git-on-ec2/