Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a main template like website I have made that will allow me to quickly roll out and make new websites on demand when I need them, for my personal use.

I'm wondering what is the best practice when using a Git repo is for this practice. My goal is that if for example down the road I'd like to make a change to all the sites at once, I can simply change the master (Repo) and have this change applied to all other versions of the template.

Currently I have my template hosted privately on BitBucket. I'm assuming it is best to git clone the repo, and then makes changes on the clone. Then when I make changes to the template I do a git pull on the sites. Is this is the ideal approach, or are there better methods to do this?

share|improve this question
1  
You may want to look into git branches, those would do exactly this. You would have a master branch and several branches from that. Then a simple git rebase master would pull the changes from the master branch into a sub branch. –  thorsten müller May 12 '13 at 19:50
    
@thorstenmüller From my understanding, a branch would not allow for unique folder locations for each branch? –  Fogest May 12 '13 at 20:05
add comment

2 Answers

up vote 1 down vote accepted

What you might want to look at is multiple repositories here forked off of a main development template line. This lets you keep some centralized templating while letting the downstream projects keep a bit more in control of their own destiny -- including holding patches to the core if you need to roll that way.

We used a strategy like this for a half-dozen or so wordpress sites to great effect, we could get worpdress security updates deployed across all projects in minutes. I will echo @Aaronaught here -- unless you are very disciplined in the way you develop the core template this will be tricky to pull off. Wordpress, over the years, has got that discipline so it worked out great there.

share|improve this answer
    
The core template would only make changes such as styling changes, or addition of new Javascript widgets. Added things would rely on a site-specific change to implement it. Any changes I make would be designed not to break sites. I like your idea of using forks. I'm slightly new to git, but isn't forking only used on the web interface? Is a fork equivalent to a pull? –  Fogest May 12 '13 at 20:28
    
Forks begat pulls -- by forking a repository you are creating a 2nd related copy. You can then pull in upstream changes -- from the repository you forked from -- by pulling from the original repo. Also don't underestimate how much these things will end up differing between each of the forks. –  Wyatt Barnett May 13 '13 at 0:34
    
It may have helped to note in my original post, that this is mostly being used for an easy method to quickly deploy personal webpages. I make a lot of websites for my school for upcoming events and all these sites have the same style of themes. The only thing that changes is some added pages (works fine with way I laid this out) and some little widgets like poll voting. The template I'm forking from is not designed with huge flexibility in mind, and I'm fine with that. Thanks for your answer. –  Fogest May 13 '13 at 1:01
add comment

I think you're confusing the role of source control with the role of software architecture and proper dependency management.

If you've got a templating system, or just a template, that you want to be able to roll out to multiple sites, then you design it as a standalone framework which can be customized in certain predictable ways. This is how CMSes like WordPress already work. If you need to change the template and want that change to propagate to all sites, then you simply release a new version of the framework and update the sites that are based on it.

Cloning a repository is primarily meant as a tool to get multiple developers working on the same project. I think you're going to run into many headaches in the more distant future if you try to use that model for working on several completely different projects. Without the encapsulation provided by a real framework, it's almost certain that changes will be made to the templated sites that essentially rev-lock them, and while that's always a risk, it's exacerbated here by the ambiguity between modification and extension, a clear violation of the Open-Closed Principle. While that principle is specific to OOP, the general concept applies to all software.

Branches would probably make for a model that's easier to understand, although technically in Git you can still do all of the same things with multiple repositories, albeit more awkwardly, by simply adding local ones as remotes. I'm not sure why you'd want to, but it's possible.

It's not good design, though. In order to keep the sites maintainable, you want a clear separation of concerns between framework/templates, content/customization, and site deployment. It sounds like you're conflating them all and I'd urge you to reconsider before adopting a risky and bug-prone approach that depends entirely on source control. Git is great but it's not perfect, and even when a merge has 0 conflicts it can still break your site if the changes in both repositories are significant.

share|improve this answer
    
Well, what I have is essentially more like a theme, with some framework like design. The changes that would be made to the template would only if anything be things like CSS changes. I don't want to have to copy CSS files over when I could use Git to do this for me. The changes I make would not break things. Since this template is more just like a theme, if I plan to change a lot from the original, then I don't plan to use this template. In reality using a framework or making one is better, but I'm wondering how I should do this using Git. –  Fogest May 12 '13 at 20:24
    
@Fogest: When you say "I don't want to have to copy CSS files over when I could use Git to do this for me" - that really is a false dilemma, you say that as if they are the only two options available but they are in fact probably the worst two options, with Git being a slightly worse option than just copying the files. Almost every major framework has a package management tool (npm, NuGet, rubygems, etc.) and many of them have packages that are very similar to what you're describing (for example, Twitter Bootstrap). –  Aaronaught May 12 '13 at 20:32
    
A simple thought experiment: Would you want to fork your entire site off of the jQuery repository and try to use that to "cascade" updates from jQuery to your own site? Or would you just use the distribution or better yet use the CDN? –  Aaronaught May 12 '13 at 20:34
    
You have a very valid point with what you are saying, though I don't really want to spend the time right now trying to turn this into a framework, or build it with a framework. It is a pretty simple template and I want to keep this approach simple. –  Fogest May 12 '13 at 20:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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