Useful when you’re working on a new feature/fixing a bug and don’t want to mess with master branch. Especially in teams, everyone will be working on different features, thus different branches. I would akin branching to an ‘alternate timeline/universe’.
Suppose you want a separate branch to work on an analytics feature. Let’s create a branch called feature-analytics.
git checkout -b feature-analytics
After committing all your changes, you’ve decided you’re ready to merge with the master branch. First, you go back to the master branch with checkout,
git checkout master
Now, you can merge your analytics branch with your master branch,
git merge feature-analytics -m "Merge analytics feature"
And once you no longer need the branch, you may delete it like this,
git branch -d feature-analytics
Easy peasy.