Before going over how to create a Git branch using the CLI, we will review the much simpler process using the visual context provided by the cross-platform GitKraken Git GUI.
Spend less time on common workflow tasks, like creating new branches, so you can reserve your mental energy for the hard stuff.
How do you create a branch in GitKraken?
To create a new Git branch in GitKraken, you will simply right-click on any branch or commit and select Create branch here.
ProTip: GitKraken will automatically checkout the branch for you immediately after the branch has been created, so you can get straight to work on the right file.
Alternatively, you can use Cmd/Ctrl + P to launch the GitKraken Fuzzy Finder and type “create branch”. This will jump you straight into the create branch field for whichever reference you currently have checked out.
Managing branches can get cumbersome in the terminal. Let GitKraken do the organizing so you can focus on the code.
How do you create a Git branch in the command line?
If you’re using the terminal, you will use the git branch command followed by your desired branch name to create a Git branch in your repository.
It should look something like this:
git branch feature-A
This will create a Git branch on your currently checked-out reference.
How do you view your Git branch list?
If you’re not using GitKraken, you won’t have the benefit of seeing all of your repository’s branches in your main UI. If you’re using the CLI, you can run the git branch command to view a list of your local branches and confirm that your newly created branch appears.
How do you checkout a new Git branch?
After you have created a Git branch, you can use the Git checkout command followed by the branch name to checkout that branch.
git checkout feature-A
How do you create and checkout a Git branch at the same time?
Once you’re comfortable with how to create a Git branch, you will likely enjoy the ability to create a new branch and checkout the branch using one command.
You can combine the two actions of creating and checking out a branch in Git with:
git checkout -b <branch name>
This will create a new branch and immediately checkout the branch.