When should I create a new branch?

I am using git as the first time for version control system. I am starting a new project and, therefore, experimenting a bit with the technologies used in the project (examples of hello world ...) I want to create something like a branch "playground". Is it common to create a new branch "playground" or do I need to create a folder named playground in the main branch?

considers

+16
git branch versioning
source share
5 answers

You should create a new branch when you are doing development work that is experimental. So in your script, be sure to create a new branch, not a folder inside master. If you created your sandbox as a directory in the wizard, it will be there until you delete it with git. The presence of dead code in the main branch is by no means ideal, because it can confuse other developers and can simply rot throughout the life of the application.

If your team encountered an error, you would not want them to spend time studying experimental work to determine if an error exists in this directory. Creating a new branch allows you to isolate your changes from the main branch. If your experiments are successful, you always have the opportunity to merge your changes into the main branch. If things are not going so well, you can always drop the branch or leave it in your local storage.

+24
source share

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

Both use the so-called theme branches to create new functions that combine when they are ready / accepted.

The Github thread is pretty simple, and obviously what Github uses. Gitflow is a bit more complicated and more suitable when you need to support multiple versions of an application where patches can be applied.

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

+6
source share

You should consider creating new branches and working on them in the following cases: -

  • If you want to work / test something in a sandbox environment.

  • Itโ€™s good practice to keep your commits in nature. So often, commits from you can disrupt the development area of โ€‹โ€‹others. Therefore, it is better to complete your work on a branch, and then merge your branch into the main branch. [Tip] . Remember to keep the branch in sync with the main branch, often adding the main branch to your branch. Thus, at a later point in time, you do not have much to unite manually.

  • You want to solve a problem. It is better to solve it on another branch and merge it later.

  • If your commit does not meet the requirements / breaks your assembly, the assembly of the assembly will not be affected. Therefore, I prefer to use at least two branches of the branch branch and prod. When everything is fully tested, merge the dev branch into the production branch.

+4
source share

You have to defiantly learn by experimenting, but in a repo on the playground.
A catalog of playgrounds in a repo will have less benefit.
Play, make some mistakes, learn some things - delete them several times and go into the wild.

eg.

$ mkdir playground $ git init $ touch hello-world $ git add hello-world $ git commit -m "my first commit" $ git branch goodbye $ git checkout goodbye $ echo "goodbye" | cat >>hello-world $ git status $ git add hello-world $ git commit -m "goodbye commit" $ git merge master 

I also recommend grabbing the plug of the active project in your chosen language from GitHub and letting it merge, reload, etc. with real code.

+3
source share

A common way is to use the main branch as a living branch. Then you create new branches in the wizard and work on them (function branches). After you finish your work, you will merge the changes back to your master.

You can create new remote branches, such as the dev branch, and merge your changes into this branch when you want only a preview. There are several ways, but there is a lot of information about google.

Branching and merging
Git branching model

+1
source share

All Articles