1

I am maintaining and developing a Drupal website and have a testing/development version of the site in a subfolder of drupal instalation. I started to learn git and I am wondering about how could I use it in my development process. I came up with following solution:

Make a git repository for live site and clone it in the test subfolder (which will be added into live site's .gitignore file). Make some development in the test directory, test it and when I'm satisfied, switch to the live site repository, fetch and merge the changes.

Since I am a newbie to git, I'd like to know if this approach can be succesfully used, or if not, which aspects should I change/or come up with completely different solution.

  • Are you self-hosting git for a reason? A remote service offers lots of advantages (although some draw backs as well). – acrosman May 24 '16 at 13:31
0

I would use a post-update hook that will pull changes into the webroot and perhaps also run some other commands like clearing the caches etc.

First you need to create a bare repository:

mkdir /var/git/<repo-production.git>
cd /var/git/<repo-production.git>
git init --bare
cp hooks/post-update.sample hooks/post-update
chmod +x hooks/post-update

You then need to modifiy your post-update to something like:

#!/bin/sh
cd /var/www/<your_www_root> || exit
unset GIT_DIR
git pull hub master
# if you have drush installed you clear caches here
# drush cc all
exec git update-server-info

Then you need to clone out the repository in your webroot:

cd /var/www
git clone /var/git/<repo-production.git> <your_www_root>
cd <your_www_root>
git remote rename origin hub

Then on your local machine you add the remote like this:

git remote add production ssh://root@example.com:/var/git/<repo-production.git>

Of course you need to change the above to match your own username, hostname and path to your repository.

You should now be able to push changes to the remote repository, than in turn will deploy any changes into the webroot.

git push production

Notice that you can setup another bare repository for your staging environment and modify the above so it checkout the code to a different location. A nice approach would then be to add it using git remote add staging <path_to_staging_repoistory>. Done this you are able to push your code either to production using git push production or to staging using git push staging.

| improve this answer | |
0

Look into Git-Flow http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/ for a very logical method of dealing with branches and server environments. You can either adopt the methodology and handle the branches yourself or you can download a git module that does it for you from https://github.com/nvie/gitflow

Basically you have a 'master' branch that contains your production code and you use git pull to pull it to your PROD server. You also have a 'develop' branch that contains your test code for your DEV server. Once code is ready for production, merge it into 'master', push, then pull to PROD.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.