init: git branch
This video we'll learn how to use git branch
.
Branching is something that is super lightweight in Git.
By default, every Git repository creates a branch named master.
We can see this in my command prompt, but also by running git status
.
In addition, we can verify this by running:
git branch ––list
This outputs all of our local branches and highlight the branch we are currently on with an asterisk.
Let's create a few branches to build up our branch list.
We can do so by running git branch
and passing it a name for the branch.
While there are only a few restrictions on branch names, I prefer to keep it simply and only use lowercase letters, numbers, and dashes.
In this case, I'll create branch-1 by running:
git branch branch-1
We can list the branches again to verify that this was created. This time we'll drop the –-list
option as this is the default behavior.
So, we'll just run: git branch
We can remove a branch by using the -d
option.
First, let's create a branch to remove, so I'll run
git branch remove-me
We'll verify the branch was created by running git branch
.
And now I'll remove it by running:
git branch -d remove–me
We'll verify the branch was removed by running git branch
.
git branch
is a command you probably won't use very often. However, you will use branches often.
So I recommend continuing onto Master: git branch to learn more about what a branch is.