Using Git to Maintain Your Website

By Daniel Miessler on December 16th, 2008: Tagged as Git | Programming
  • Is svn that bad? I used for a few projects (personal projects so it's just me) and I find it easy to use. Never really had any problems. I have it on at my host (at antoniocs.org) and with tortoise I can commit or update easily.

  • I have started doing exactly this with Mercurial and was wondering why more people weren't doing it. Is there any downside to it? None that I can see.

  • You may want to remind users that when they issue the clone command (git clone ssh://yoursite.com/path/to/html.git), they need to specify the full path to their git repository. I was getting the "fatal: The remote end hung up unexpectedly" error until I realized I was not specifying the full path on the remote server filesystem.
  • post-update must be in html.git/hooks, not html.git.
  • Yann
    I'm in the midst of converting to Git and looking around on the web, I see that everyone seem to do dev -> bare repo -> live site. I"m new to git and there's one thing I don't understand... Why not make the live site the repo, what's the use of the bare repo in the middle?

    Any clarification on that much appreciated :)
  • r0s
    @ Yann
    That's my thought too.
    Shouldn't you simply branch your project at the main repo, instead of having an *almost* live copy on the server?
    Also it seems counter to the distributed model of Git, that is, each developer has the whole project, so they can pull from each other to see code and collaborate.
    That second point may be quite misinformed.
    Anyone know the answer?
  • r0s
    A little more info...
    Git can manage multiple projects under a main repository called Submodules.
    With this and branches, there seems to be no need for the bare repo.
    This is the way I'm planning to use it.
    If I find problems I'll try to report back.
  • Jason Diehl
    I've been looking around at different topics on using Git to maintain a website. My Problem is that I don't understand how with all the branching and everything else to actually make it effective. For example, I have my main branch, which is my live site, set it up so that when it's pushed it updates the live site. Then I can have a development branch for trying out changes and such, this is awesome, but after I make the changes how do I try them out for like a PHP dynamic site? I assume I would create another repo for development that updates a development server or space, so I make my changes, push to the dev, then I can test them there? Okay then with git again it's really easy to branch again for maybe a quick patch, or to try another little change out. But where do I push that to test those changes? Do I need to create yet another repo that updates another web space somewhere, which would only be short lived, so seems like a lot of work. I guess I really really like the idea of Git, but don't understand how to utilize the branching and still be able to test changes. Or do you just not use branching so much in this kind of situation? Or is it really like a few comments I've seen online where people say "it's stupid to update a website with git"?
  • I believe there is a significant privacy problem with "live" html directory being a git repository - it contains the .git directory, which could be copied by a malicious (or just curious) user to gain access to private data (database access credentials in the simplest case).

    Of course, this requires AllowDirectoryIndexes (or whatever is the correct name) set to On, but still...
  • Ryan
    Thank you for your post; it has been very helpful! I am in the process of making this set-up for myself, and it seems that the post-update hook you give has changed yesterday or today; is that correct? The old was:

    WORKDIR="/your/live/html/directory/"
    export GIT_DIR="$WORKDIR/.git"
    pushd $WORKDIR > /dev/null
    git pull
    popd > /dev/null

    And the new is:

    cd ../htdocs
    env -i git pull

    It seems so, but just to clarify, is the new/replacement simply a more efficient way of doing the same thing? Thanks again!
  • Yes, it's a much better way of doing it.
  • hey

    thanks for the tip. I'll try it
  • Frank C. Tannehill
    Hello Daniel! Can you please explain why it's better to make the changes offline rather than directly on the site? Why is it better to change the copy and then upload it? Does it has something to do with how the search engines see the site? Can it affect the rankings?
    ___________
    Frank Tannehill - domain
  • With git you have a history of all changes, and you can roll back to
    specific points.
blog comments powered by Disqus

Twitter Microblog

twitter_icon      facebook_icon

Sample Original Content


Information Security

Tutorials and Primers

Culture & Society

Technology & Science

Politics

Philosophy & Religion

Miscellaneous

Tools & Projects


Blog Archives