When should i create a new branch?

Moonlit picture Moonlit · Mar 26, 2013 · Viewed 13.7k times · Source

I am using git as the first time for a versioning system. I am starting a new project, and therefore to experiment a little bit with the technologies used in the project (hello world examples...) i want to create something like a "playground" branch. Is it common to create a new branch "playground" or should i just create a folder named playground in the master branch?

regards

Answer

Kevin Bowersox picture Kevin Bowersox · Mar 26, 2013

You should create a new branch when you're doing development work that is somewhat experimental in nature. So in your scenario definitely create a new branch and not a folder within master. If you created your sandbox work as a directory in the master, it's going to reside there until you remove it using git. Having dead code sitting in the master branch is not ideal by any means, since it can confuse other developers and may just sit there rotting for the lifetime of the application.

If your team were to experience a bug, you wouldn't want them to waste time exploring the experimental work to determine if the bug existed within that directory. Creating a new branch allows you to isolate your changes from the master branch. If your experimentation goes well you always have the option to merge your changes into the master branch. If things don't go so well you can always discard the branch or keep it within your local repository.