7

I'm a designer that's looking to ease the pain of managing the development of my websites. I've only recently discovered Git and so far it has been very easy to pick up. From my understanding it is possible to use Git as a way of deploying these changes using two or more repositories; one of which is the master. I'm specifically interested in having a development environment, a testing environment and a production site.

So I have a few questions:

Is it acceptable to use Git in this way?

Which is better; storing the master repository on your local machine and pushing changes to the production and testing server? Or is it better to store the master on your production sever and pull to your local machine to make changes?

If so how would you accomplish either method?

2 Answers 2

3

There might be a little bit of confusion here so i'll try to clarify things.

A repository is just a copy of your code. You can have several copies of your code (that is, several copies of your repository, for example: One on your development machine, one on your testing server, and one on your production server). Everything is coming from the same code, you just could have each repository at different commits (a set of changes) or a different branch.

My suggestion would be to work like this. You create a repository with your code by doing in the root directory of the project you want to version with git.

git init

Now, you can create several branches of your code. One would be called "master" (this is usually how people name it) and it is used to store production code. Another branch can be called "development". So, when you are going to start playing with your website, you switch to development branch in your local copy of your repository, make the changes, commit to that branch, and push those changes to the repository in your test server (which you would usually keep set in the "development" branch). You test your code, and then when you feel it is ok, you merge your development changes to master, and then push that to your production server repository (which would be usually in "master" branch).

I would strongly suggest that you use github.com, it could really simplify things and also help you to keep remote safe copies of your code. Also, you don't need to create git servers to be able to push changes to each copy of your code but you just update your github copy, and later you can pull those changes from each version of your code (i.e testing and production).

All i explained here could be a little bit confusion, you can check a book to understand the difference between a repository itself and a branch in a repository. Git is a great choice to keep your code organized. If you decide to go with it, you could take a look at this site http://gitimmersion.com/

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. That site looks useful, I'll give it a read. Just to clarify, you can merge changes from one branch to another without having to merge them back in with the master?
Yes, you can merge commits into any other branch independently, no need for master to be a "point in between".
Great. In your example the master repository is decentralized from the whole setup ie. it isn't used as the production server (or live site). What advantage does this have? Many thanks.
@Sevenupcan I can't really understand what you mean. Take a look at this, may be that can clarify things nvie.com/posts/a-successful-git-branching-model If you don't find an answer to your question in that link, please rephrase it and i'll try my best to answer it :)
This answers my question and more. Thanks! :)
3

It's a great idea to use Git like this. From what I've seen, most people have the master on their local machines and push to a production/testing server.

There's a nice guide to using Git for this purpose here: http://toroid.org/ams/git-website-howto

If you want a testing machine as well, do the steps described in 'The remote repository' again on a different machine and add it as a remote with a different name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.