> For the complete documentation index, see [llms.txt](https://raviram.gitbook.io/version-control/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://raviram.gitbook.io/version-control/git-moving-ahead/group-2/branching-demo.md).

# Branching Demo

## Presentation

{% embed url="<https://docs.google.com/presentation/d/1G1q_tx8Szc7o7MhurYEw4O59Eoxu-eMVwgtetIlP6Zg/edit#slide=id.g92a1ad2113_0_137>" %}

## Branching in a Nutshell

Nearly every VCS has some form of branching support.&#x20;

1. Branching means you diverge from the main line of development and continue to do work without messing with that main line.&#x20;
2. In many VCS tools, this is a somewhat expensive process, often requiring you to create a new copy of your source code directory, which can take a long time for large projects.
3. Some people refer to Git’s branching model as its “killer feature,” and it certainly sets Git apart in the VCS community.&#x20;
4. The way Git branches is incredibly lightweight, making branching operations nearly instantaneous,&#x20;
5. Switching back and forth between branches generally just as fast.&#x20;
6. Unlike many other VCSs, Git encourages workflows that branch and merge often, even multiple times in a day.&#x20;
7. Understanding and mastering this feature gives you a powerful and unique tool and can entirely change the way that you develop.

{% hint style="info" %}
Some people refer to Git’s branching model as its “killer feature,” and it certainly sets Git apart in the VCS community!
{% endhint %}

## The idea behind branching&#x20;

The idea is that your branches are at various levels of stability; when they reach a more stable level, they’re merged into the **branch above them**. Again, having multiple long-running branches isn’t necessary, but it’s often helpful, especially when you’re dealing with very large or complex projects

<figure><img src="https://2260207797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDxKw7cN7VlJOaD4AQYEa%2Fuploads%2FA48nzve6kiohaA50CfRQ%2Fimage.png?alt=media&amp;token=ef1fcd27-1b7c-4198-a731-d131c4a5daac" alt=""><figcaption><p>progressive-stability branching</p></figcaption></figure>

## Let us work on a scenario <a href="#basic_branching_and_merging" id="basic_branching_and_merging"></a>

Let’s go through a simple example of branching and merging with a workflow that you might use in the real world. You’ll follow these steps:

1. Do some work on a website.
2. Create a branch for a new user story you’re working on.
3. Do some work in that branch.

At this stage, you’ll receive a call that another issue is critical and you need a hotfix. You’ll do the following:

1. Switch to your production branch.
2. Create a branch to add the hotfix.
3. After it’s tested, merge the hotfix branch, and push to production.
4. Switch back to your original user story and continue working.

### Let us create a repo to begin with

Let us create a file and put some contents in it, as shown in the commands below

```
mkdir gitdemo1
cd gitdemo1
```

```
git init
```

```
echo "this is my code file" > file1.txt 
```

```
cat file1.txt
```

```
git add .
git commit -m C0
```

```
echo "this is line 1" >> file1.txt
```

```
git commit -am C1
```

```
echo "this is line 2" >> file1.txt
```

```
git commit -am C2
```

```
git log --oneline
```
