Using Git to Maintain Your Website

By Daniel Miessler on December 16th, 2008: Tagged as Git | Programming
  • Pingback: A git Primer | dmiessler.com

  • http://antoniocs.org/ antoniocs

    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.

  • http://antoniocs.org antoniocs

    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.

  • http://rrees.wordpress.com/ Robert Rees

    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.

  • http://rrees.wordpress.com Robert Rees

    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.

  • Pingback: Git Website Management Post Update | dmiessler.com

  • Pingback: Git weekly links: 2008-51 « git blog

  • Pingback: Six Resources To Study And Master Git Source Control

  • Pingback: links for 2009-01-04 « Bloggitation

  • http://pixelchimp.net Drew Reece

    Another article using the same technique is … http://joemaller.com/2008/11/25/a-web-focused-g
    I'm working on something similar for Drupal sites. Do you have issues with server created content? I also wonder if versioning the DB's would be useful too using a separate repo. Git seems to be remarkably efficient with space.

  • http://dmiessler.com/ Daniel Miessler

    I don't have any issues with this method, no. If I change something on the server side that I want to sync, I just run git add, git commit, git push, and then git pull from my dev box. Good to go.

  • http://dmiessler.com/ Daniel Miessler

    I don't know of any downsides other than perhaps initial setup time (which is very low once you get comfortable with it). I am very happy with the system.

  • http://dmiessler.com/ Daniel Miessler

    > Is SVN that bad?

    Perhaps not, but I much prefer this system using git. But again, if you try this and like SVN better–so be it. I think all the religion surrounding tools is silly.

  • Pingback: Scott Jarkoff :: Using Git to Maintain Your Website

  • http://pixelchimp.net Drew Reece

    Thanks, that's useful to know.

    It seems to work well on a test setup, I'm waiting for Git to be installed on the server (because it's easier than installing for multiple domains on one server).

    Do you use Git excludes to avoid overwriting site specific files? I want to use it with Drupal which uses a settings.php for the DB & config. I think I would like them tracked in Git, but not pushed & pulled between different repos. I wonder if the hub could filter them?
    Do you have this issue?

  • http://www.LCN.com/web_hosting Web Hosting

    Thanks mate, just what i was looking for

  • Grateful

    This helped me (git newbie) immensely. I set this up in combination with the EGit/JGit Eclipse plugin – for anyone else Eclipse-ifying a static website with Git, also look at: http://github.com/guides/using-the-egit-eclipse
    One note, you should add a default .project (copy one from another project & change the xml name tag) in the root of the to-be-repo'd folder before doing 'git add .', or else Eclipse won't be able to load the project by importing!

  • Pingback: The Real Reason Git is Great | dmiessler.com

  • rocku

    And what if I need special file-mode and uid/gid for the scripts in a live website? Git doesn't preserve thoes. I could, of course, set up a few hooks to chmod/chown every file but this seems a bit overkill. Are there any known workarounds for this issue?

  • drew_reece

    Rocku,

    Checkout the script in the contrib/hooks section of Git source.

    The script will read permissions into a file in the repo & write them out too. It just requires hooks to call the script.

  • Pingback: How to Maintain Static Sites with Git & Jekyll | Biodegradable Geek

  • Tatlar

    Can you outline how you would use this approach if you have a typical website with lots of files, images etc that should be ignored? I have a site that has a large directory that is constantly updated with a bunch of html and gif files generated elsewhere and rsynced over that should not get version controlled.

    Do I need to add them into the repo in the git init? And then ignore them thereafter?

  • http://dmiessler.com/ Daniel Miessler

    I've not implemented this myself, but there is a .gitignore file that you can use for this. I'd have to check out the usage, though…

  • Tatlar

    Can you outline how you would use this approach if you have a typical website with lots of files, images etc that should be ignored? I have a site that has a large directory that is constantly updated with a bunch of html and gif files generated elsewhere and rsynced over that should not get version controlled.

    Do I need to add them into the repo in the git init? And then ignore them thereafter?

  • http://dmiessler.com/ Daniel Miessler

    I've not implemented this myself, but there is a .gitignore file that you can use for this. I'd have to check out the usage, though…

  • David

    Great tutorial. Thanks. Found similar at http://joemaller.com/2008/11/25/a-web-focused-g….
    Not sure what are the advantages of using in hooks 'pushd' / 'popd' or just 'unset GIT_DIR' which way is better?

  • http://jkoops.com/ Jed Koops

    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.

  • http://humanerr0r.blogspot.com/ Anthony

    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 :)

  • 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.

  • Pingback: επιστροφή στις “στατικές” σελίδες; – vrypan|net|weblog

  • 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”?

  • http://bogdan.org.ua/ Bogdan

    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!

  • http://danielmiessler.com/ Daniel Miessler

    Yes, it's a much better way of doing it.

  • Pingback: 小鱼笔记 » 使用Git维护你的网站

  • Pingback: Using Git to Maintain Your Website | danielmiessler.com « Netcrema – creme de la social news via digg + delicious + stumpleupon + reddit

  • Pingback: Using Git to Maintain Your Website: http… « Dc's Notes

  • Pingback: Using Git to Maintain Your Website | danielmiessler.com : Popular Links : eConsultant

  • Pingback: Destillat KW50-2009 | duetsch.info - GNU/Linux, Open Source, Softwareentwicklung, Methodik und Vim.

  • http://www.tvledinfo.com.br/ dowlie

    hey

    thanks for the tip. I'll try it

  • Pingback: git top links: 2010-1 « git blog

  • Pingback: A tcpdump Tutorial / Primer « The world apart

  • 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

  • http://danielmiessler.com/ Daniel Miessler

    With git you have a history of all changes, and you can roll back to
    specific points.

  • http://www.antiquedrawerhandles.net antique drawer handles

    I'll post the same information to my blog, thanks for ideas and great article.

  • http://andreas-krey.blogspot.com Andreas Krey

    You could do 'git clone you@yoursite.com:rel/to/home.git'. 'you@' optional if usernames are the same, or you set up something in .ssh/config; I regularly just have 'devbox:somerepo.git' as remote 'url'.

  • http://www.equines4us.com Horses For Sale

    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.


Top

Popular

Information Security / Technology

Politics

Philosophy & Religion

Technology & Science

Culture & Society

Miscellaneous

Arguments

Projects

Collections

Twitter

What I'm Reading

Favorite Books and Essays

Top Blog Categories

Inputs