tags:

views:

193

answers:

4

I just started using Git recently and I was reading up on Git best practices and it seems the most common one is to never work out of your master branch, always create a separate branch and work out of that. I'm wondering if this is only true when working with other developers or if this is something I should be doing if I'm the only developer on the project. If so, why? And how often should I merge the new branch? Why is that any different than just working out of the master branch and committing changes when necessary?

Thanks so much for your wisdom!

+18  A: 

Working out of a branch maybe a good idea if - for example - you are adding a phat new feature which wont be ready for a few weeks. Whilst you are working on your new feature, the Live app cocks up. What do you do if you havent branched (or tagged) from trunk (in this case the code branch supporting live) ? you have to revert all your work and maintain copies of your changes, ready to slap them back in when you have resolved your live issue.....

brumScouse
perfect, you beat me to it
DOK
This is exactly what I do and it's been quite useful. Creating, merging, and rebasing branches is easy and makes adding new features painless. In fact if I end up on the wrong track and decide I want to abandon the feature, or do it another way, just checkout 'git checkout master' and then create another branch.
Daniel Beardsley
yeah, i can already see where working out of a branch would have saved me some time in the recent past. thanks!
BeachRunnerJoe
+8  A: 

Yes,

Working from branches lets you isolate changes that you aren't ready for integration into your stable branch.

For example: I have been working on a major new feature in a separate branch for several months. If I was not maintaining a separate branch, it would have been much more difficult for me to issue minor updates and fixes.

mikerobi
+5  A: 

The beauty of git is that you don't have to do anything. There is no 'best' way to do something because it depends on you, your situation, your project, etc.

So, no, don't do anything that doesn't make sense to you. That said, keeping features in topic branches can be good for future-you reading the code and commit history. And, as others have said, definitely keep stuff in topic branches if you're working on two things in parallel.

thenduks
Best point in the discusion so far. Git even allows you to act like you have an old-fashshioned single-repository system if you want.
T.E.D.
Thanks, and I agree. The best part about distributed revision control is that you can work in whatever style you want and _not have to fight with the tool about it_!
thenduks
+2  A: 

One good reason I can think of is that having a master branch allows you to point users to the master for pulling down releases, rather than having them pull straight from your working repository. That allows you to feel free to commit changes to your working repository that may not be quite ready for prime-time (eg: not fullly tested).

T.E.D.