# Concept of Branches

&#x20;   ▪ Branches are used for better collaboration&#x20;

&#x20;   ▪ A "main" branch (also called "master") is created by default when a new repository is initialized&#x20;

&#x20;   ▪ Each developer can then create temporary branches e.g. for a feature or bugfix and work on it without worrying to break the main branch

![Here we have 4 different branches](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FojQsO5FzNDTPNfCf2N90%2Fimage.png?alt=media\&token=22b24f76-9746-4a1f-a2c1-902a6e6abd07)

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2Fiq1EstJfhpfTucIpgWUW%2FScreen%20Shot%202022-05-14%20at%2018.07.20.png?alt=media\&token=0179a8d8-34c6-446e-a893-268e032f77b0) ![Exactly same code copied from master](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FeQ6SzkLWsuyAxQi8dHaS%2FScreen%20Shot%202022-05-14%20at%2018.29.15.png?alt=media\&token=0cc0bc4c-e171-4a0f-b4ab-a4ae41f71140)

![Creating branch with GUI](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FYajmTTokpWp9poXHnfUS%2FScreen%20Shot%202022-05-14%20at%2017.53.29.png?alt=media\&token=96c28497-befa-44ca-baf3-605d16586af9)

![Creating branch with GUI](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FJwfea3EHtVcRcY9ghAXs%2FScreen%20Shot%202022-05-14%20at%2017.54.47.png?alt=media\&token=781d9de7-6d7c-4e35-8a12-f78d990e267f)

```bash
git pull # will pull down the changes from the remote repo to our local repo, and merge them with a local branch.
```

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2Fu8Tssi1zrEq59VTf0Hwa%2Fimage.png?alt=media\&token=990a6696-59e3-4c56-a6ad-10bdf9030405)

```bash
git checkout # allows restoring tree files or switching branches
```

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2Fh2uXwECeakoSSaFkx178%2Fimage.png?alt=media\&token=b264b797-9ad5-41a8-9d35-8545ffd1d79e)

```bash
git checkout -b # creating and switching to a new branch
```

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FrnFFFIq1gj2AZD6QUyn8%2Fimage.png?alt=media\&token=942a771a-47a9-4846-baf2-dd103b802002)

![We have added new branch locally](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FKTYQ5J80fwqeqiACMfdE%2Fimage.png?alt=media\&token=231f9b47-2889-47dd-ac2a-9a3c2b791bba) ![Cant see branch in the remote repo](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FFGzqeg4McM4NXHUPHn6b%2Fimage.png?alt=media\&token=e2d8d2e5-ac33-452f-bf8c-a0211a65af4d)

```bash
git push # sends our changes to the remote repo.
```

{% hint style="info" %}
Git only allows to push if your changes don't cause a conflict.
{% endhint %}

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FD0Nc1XM70iOZRFli7MnH%2FScreen%20Shot%202022-05-14%20at%2019.03.31.png?alt=media\&token=1bdae14c-f4a1-46d6-b0f2-13065f7c9d1a)

#### Master(ready for production) and Develop branch

&#x20;   ▪ dev branch : **intermediary master**

&#x20;   ▪ during sprint : features and bug  merge into dev branch

&#x20;   ▪ <mark style="color:red;">**end of sprint**</mark> : merge into master branch

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FSkBWAWnA3IM7EnAqzyPD%2Fimage.png?alt=media\&token=0e29777d-d2a5-42e9-8ab4-378c612a661e)

&#x20;   ▪ with MASTER branch

&#x20;       ● <mark style="color:green;">**only master branch for continuous integration/delivery**</mark>&#x20;

&#x20;       ● pipeline is triggered whenever feature/bugfix code is merged into master

&#x20;   ▪ with DEV branch

&#x20;       ● deploying every single feature/bugfix&#x20;

&#x20;       ● features/bugfixes are collected in dev branch&#x20;

&#x20;       ● dev branch often becomes "work in progress" branch
