Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should i create a new branch?

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

like image 313
Moonlit Avatar asked Mar 26 '13 09:03

Moonlit


People also ask

Why should I create a new branch Git?

In Git, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes.

Should I make a new branch for every feature?

It's a good practice to create a new branch for every new bit of work you start doing, even if it's a very small one. It's especially useful to create a new branch for every new feature you start working on. Branches are of course disposable, you can always remove them.

When should you branch?

You should branch whenever you cannot pursue and record two development efforts in one branch. (without having an horribly complicated history to maintain). A branch can be useful even if you are the only one working on the source code, or if you are many.

When should I branch in github?

A Git branch is essentially an independent line of development. You can take advantage of branching when working on new features or bug fixes because it isolates your work from that of other team members. A git branch is an independent line of development taken from the same source code.


2 Answers

Branches have many uses, and it depends a bit on your workflow. Two commonly used workflows are:

  • github flow
  • gitflow

Both use so called topic branches to build new features in, which get merged back once ready / accepted.

Github flow is fairly simple, and is obviously what github uses. Gitflow is a bit more complex, and is more suited when you need to support several versions of an app, where hotfixes can be applied.

In the end, it's a matter of preference what kind of workflow you use, but because creating branches is very cheap in git, it doesn't really matter how many branches you create (and eventually, delete again).

like image 35
Ikke Avatar answered Sep 18 '22 05:09

Ikke


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.

like image 97
Kevin Bowersox Avatar answered Sep 19 '22 05:09

Kevin Bowersox