Drupal and GIT
During this year I've been moving my projects to GIT. While my private projects are on this server, my public ones are on GitHub as Open Source. Git is a really wonderful version control tool for any kind of project. It makes it easy for me to deploy, maintain and update my current sites. I just wish there could be a way to include the database on it. In this post I will explain how I'm using GIT to manage a Drupal site on both local and live environment. And since most people already have a site working, I will explain starting from an existing site.
Create the repository
The very first thing is going to the actual site, in my server this site is in: /var/www/sitename.com/public
cd /var/www/sitename.com/public git init echo "sites/default/settings.php" >> .gitignore
You can also run this if you want to ignore the files folder (that's really up to you)
echo "sites/default/files" >> .gitignore
Then you have to add all files to the repository and make the first commit
git add . git commit -m "Initial commit for this site"
Making the site remotely available
Once you have your local repository working on your server it's time to push this to another place. This is asuming that you have a 'git' user somewhere else and you have access to SSH. I use my own server so I can actually change the address to localhost
scp -rp .git git@yourreposerver.com:sitename.git
The last line is really dependent on your current config. In my case I use this:
scp -rp .git git@ivansotof.com:sites/sitename.git
You can google a little about SCP command if you are not familiar with it. It will ask for a password since it's using SSH for copying the .git folder. It will take a while copying everything up to that server but when it's done you just need to add a remote entry to the local repo.
git remote add origin git@yourreposerver.com/sitename.git
And you are done copying the site.
Cloning and working on your local environment
Now that we have the live site under version control and the repository available for cloning you just need to clone it to your working environment.
git clone git@yourreposerver.com:sitename.git
It will create a folder sitename/ that will be a perfect copy of what you have on your live site. Now you can just go in and make changes to the site:
cd sitename
If you are using TextMate on OSX or E-TextEditor on Windows you can open the working folders from here. If you are not, then you should :) On OSX:
mate sites/all/
On Windows
e sites/all/
When you are done making changes:
git commit -m "Making some random changes"
Now push all changes to the remote server
git push origin master
Now go to the "live" site and just do:
git pull origin master
You should now have all latest changes working on your remote server. This is so far the setup I am using on most of my sites. I didn't include copying the database but I hope the readers already have some experience on that. Since I'm ignoring settings.php you should be able to have a configuration working on any copy of the site. If you are using a different setup, please share it :)
latest posts
About
Hi, I'm Ivan Soto Fernandez (yes, two last names). I'm a chilean web developer living in Edmonton, Canada. I'm also an anime fan, Gundams lover and gamer. Welcome to my blog.
You can read more about me or follow me on Twitter or any of the following social websites.