Insoshi open-source social networking platform wiki

Recent site activity

Working with Branches

One Git's strengths is how easily you can create and manage branches.  But when exactly should you start a new branch? And how do you avoid getting overwhelmed with branches and changes becoming scattered all over your repository?

When to Branch

Branching is a way to work on changes in parallel and isolate those changes from one another. 

With that in mind, reasons for starting a new branch can include
  • Working on feature x without having to worry about changes introduced by feature y
  • Starting down an experimental codepath
  • Supporting multiple versions of an application
Under Git, you can switch between those branches with the confidence that the changes you made will be found exactly where you want them.

When not to Branch

Just because you can create a branch doesn't always mean you should:
  • If you're working on features and fixes sequentially, you don't need a branch for each one
  • For a quick test of a minor code change, you can work on an existing branch and throw away the update if it doesn't work out
  • You can always go back to/checkout a previous commit so a new branch isn't necessary to keep a "safe" version of your code
While these examples might seem obvious once you've used Git for a while, you might initially find yourself doing any one of them depending on your habits (and paranoia) that you've picked up from other tools.  It's a question of what functionality you feel map to the "add" or "commit" commands and the level of confidence you have in everything working like it should.