Why do we need branches in git?

Is it possible to do without them?

How can I use them?

  • For what minus such questions? - etki
  • one
    Minusators are not usually announced. - Nofate ♦
  • @Etki, but is this question really good? A person is lazy to just read tons of information with examples on this topic, the question is not specific but general, you can give an answer to "my dopamine receptors every time they joyfully squeak when I type git branch newbranch in the console!" (speaking in Russian - I plod when I create a new branch). And a similar question might be "why the letter" d "in Russian, tell us more about situations where you can not do without it" (I wonder if you’ll ask such a question on EYE, they will give you an answer or they will seriously answer). - zb '12
  • one
    @eicto, the question is and does not have to be good. And this is not a standard "how do I read the file using php", which has a clear answer recorded in the documentation - this question is slightly philosophical in nature, and the author can read at least a hundred times about the git-flow, but never understand why it is more profitable than keeping everything in one branch; On the Internet, they usually write how to do it, and not why . Yes, he really can be more comfortable to keep in one branch, so he asks. -> - etki
  • one
    Maybe he thinks that he is missing something and we should ask about it. It makes no difference at all. On rya, it would be "why we need part-time turns". And, again, it would be the question "how can I use them?", And not "what function does it perform." - etki

3 answers 3

1 - Classic Turnip Model:

master is the latest stable release; dev is the current development branch;
dev-xxx is a branch of development associated with a planned future release.

2 - Classic work in team turnips:

merged updates - budded branch - you work in it - completed it - again merged updates into the original branch - merged branches - launched into a common turnip.

3 - T. n. git-flow - each bugfix and feature are made up in a separate branch, after the end of the work there is a merge with the dev-branch, otherwise the work is as in step 1, plus or minus the subtleties of budding hotfixes and their mergees. Link times , link two .

  • And why do we need point 2? In the gita with this is easier - commit yourself locally, and when you are going to upload everything to the central repository, you do git pull and git rebase, and your commits get up after the last commit in the master on the server. Collisions with a separate branch will still arise, if any. - aknew
  • one
    @aknew, mergers are also rebuild with a bang. The matter is simply in isolation, in that you can safely make a pull of the main branch, without fear of immediately running into a conflict. - etki

With the help of branches in VCS you can:

  • Implement the feature without disturbing the others.
  • Conduct moderation (coding) of a new code before directly adding it to the code base.
  • Escape from the implementation of features and fix the bug elsewhere.
  • At all to postpone the started feature until better times.
  • Receive a request for revision of the old version of the program from the customer and further support several software versions.
  • Experiment with the code without fear of breaking the build.
  • To organize the process of gradual release of the program (development - testing - release), without blocking the development of the next version.
  • Organize work with the open source community or contractor.
  • Sew a permanent automatic build from a working branch with a test run and a manual authorized release build from a release branch.

In the case of git, distributed work itself is inextricably linked with the concept of local and remote branches and the synchronization of commits between them.

    A branch in Git is simply a “sliding” pointer to one of the commits. When you create new commits, the branch pointer automatically shifts forward to the newly created commit.

    To work with Git on the simplest project with one developer, one branch is enough, but on larger projects more than one branch is used. There are various branches management strategies, such as git-flow .

    In principle, you can do without branches, creating all commits manually, after which they will be stored as lost objects. But this is an unnecessarily complex way. In addition, the garbage collector will delete them sooner or later.