Continuing with our example repo, let's create a new branch.
The proceeding command sequence will create a new branch named
new_branch and add file
new_branch_file.txt to it. Additionally, new content is added to
index.txt and an additional commit is made for that update. We now have a new branch that is 2 commits ahead of main. We must reload Gitk to reflect these changes.
This is a great learning opportunity to discuss Git's branching mechanism. Gitk displays the commits as a straight line sequence of commits. The term branch implies that we should expect a 'branch' or fork in the timeline. Git branches are different from other version control systems. In Git, a branch is a pointer to a commit. The pointer moves to commits as they are created. When you create a
git branch, you are not changing anything in the structure of the repository or the source tree. You are just creating a new pointer.
In order to compare the commits that differ between the 2 branches Gitk needs to be launched with a specified revision range. Executing
gitk main..new_branch will open Gitk with only the commits between the two branch refs
This is a powerful utility for comparing branches.