In Git, there are common misconceptions about branching. For example, some assume that a branch is a group of commits, or that a branch must diverge in the Git graph.
In fact, a branch is simply a pointer to one specific commit.
The branch pointer moves along with each new commit you make, and only diverges in the graph if a commit is made on a common ancestor commit.
The branching model offered by Git is lightweight compared to other version control systems, and helps protect you from merging unstable code into the main code base and gives you the chance to clean up your history before merging into the main branch.
Creating a new branch in Git is quick and easy.
You can create a Git branch from any commit in your commit history; this can be great if you want to make changes starting from a previous point in your project.
You can easily rename a Git branch at any time.
If you decide you no longer need it, you can delete a Git branch to clean up your repository.
As the number of branches in your Git repository grows, there will likely come a time when you will be working on multiple tasks at the same time and will need the ability to move from one branch to another.
To switch to another branch in Git, you’re going to have to checkout the branch using the git checkout command.
Now, let’s go over how branching works when you’re using a Git client to visualize your repository.
In this example, we’re working with two Git branches: dev and production; to begin work on a new feature, we need to create a feature branch off the latest commit on the dev branch.
To create a Git branch using GitKraken, right-click on the target commit and select Create branch here from the menu.
To rename a Git branch using GitKraken, simply right-click on the branch name and select Rename [branch name].
To delete a Git branch in GitKraken, right-click the branch name from the graph and select Delete [branch name].
The GitKraken Git client makes Git faster and more intuitive with its graphical user interface.