Git 101 - branching
In this article I will be talking about the basics of branching in Git, this is one of most powerful features of Git that allows you to work on multiple things, all at once in complete isolation without disturbing other work.
Creating a branch
Imagine you're currently on your master
branch and you decide you want to work on another feature without disturbing your master
branch. The way to do this is by creating a new branch:
git branch feat/awesome
Now if you type:
git branch
You'll see that there is now a new branch feat/awesome
. Now, if you want to start making commits on this new branch you will have to switch to the new branch first, this is achieved by typing:
git checkout feat/awesome
Git will let you know that the branch has been checked out by outputting:
Switched to branch 'feat/awesome'
A shortcut for the previous two commands also exist (which is what I use most of the time).
git checkout -b feat/awesome
This will create the branch feat/awesome
first and then proceed with checking out the new branch immediately.