What is Gitk? A comprehensive guide

Learn what is gitk and what is for? And also the tasks you can do inside gitk. The gitk tool helps you visualise the git repository history.

Card image cap

Hi there! In this article, you will learn what is Gitk, and when to use it? And also some of the tasks you can do inside Gitk. The Gitk tool helps you visualize and manage your git repository history. Most likely’ if you are searching for  Gitk information, you already know what Git is. Therefore this article assumes that you have an understanding of Git. 

If not, check out the article below, and come back once you read and play around with git.

Check out this git introduction.

What is gitk?

The Gitk tool will help you visually manage your repositories and see the full history of a repository. You could see your repository history using git log; however, if the repository has a long history, navigating the history through the terminal can be difficult, tedious, and far from efficient.

Using Gitk, you can do things like creating a tag, see a diff, or cherry-pick one commit. Apart from Gitk, there are a few more tools that help you visually manage a git repository. The main advantage of Gitk is free; the downside is the first UI tool that was created together with Git. That’s why the UI looks slightly out of date.

Another advantage of Gitk is that is installed together with Git. So whenever you install Git on your machine, you install Gitk as well. Therefore you don’t need to install any third-party software.

How to use Gitk?

We have seen what Gitk is, and now let’s see how to use it. You can open Gitk just by moving to the root of a git directory and then executing the command Gitk:

>> cd <replace_with_repository_path>
>> gitk

Then you should see the following:

If nothing shows up, make sure Gitk is included in the PATH environment variable.

On the left-right corner of the screen, you can see a list of the commits. You can select any commit on the list. Once you choose one commit, you will see underneath all information about the commit, like the files that changed.

Each commit has a label indicating the branch of the commit and the tag, if any.

Default behavior

By default, when you execute gitk it will only display the history of the master branch. If you like to see all branches, you will need to run the command below, adding the --all option.

>> gitk --all

After executing the command above, you will be able to see all branches existing in the repository.

What can you do in Gitk?

Gitk offers a good number of operations. You can right-click on any commit, and a context menu will pop up with the available options.

Some of the options are selectable. Other options might not be selectable because you can’t perform the specific, based on the repository state.

For example, to create a tag for a commit, you will need to click on the commit, then right-click and select “Create Tag”. Next, you need to insert the tag name. Once that’s done, a label with the tag name will appear next to the commit.

Another interesting functionality is comparing functionality. Firstly, you need to mark a commit. Then select another another commit to compare, and then clicking the option “Diff marked commit -> this” you can check the differences with the marked commits.

If you marked a commit, if you can’t find it anymore for any reason, you can right-click and select “Return to mark” and go back to the chosen commit earlier.

Another handy option available is cherry-picking. Let’s say master is the current branch; You could select another commit from the develop branch, right-click, and choose “Cherry-pick this commit.”

Conclusion

In summary, we learned that Gitk is a convenient tool that visually manages your repository history. Using Gitk you can create branches, tags, cherry-pick, compare commits, etc. And one of its advantages is that you don’t need to install anything. Gitk is installed along with Git.

I hope you enjoy this tutorial, and thank you so much for reading and supporting this blog! Happy coding!

More Interesting Articles

How to open a web browser in python

Runnable vs Callable – Find out the differences

How to Write a Tic Tac Toe Game in Java using classes

Django: order by and filter with examples

Python Errors: Nameerror name is not defined and more

Learn Ethical Hacking From Scratch Course

Become an ethical hacker that can hack computer systems like black hat hackers and secure them like security experts.

Project-Based Programming Introduction

Steady pace book with lots of worked examples. Starting with the basics, and moving to projects, data visualisation, and web applications

100% Recommended book for Java Beginners

Unique lay-out and teaching programming style helping new concepts stick in your memory

90 Specific Ways to Write Better Python

Great guide for those who want to improve their skills when writing python code. Easy to understand. Many practical examples

Grow Your Java skills as a developer

Perfect Boook for anyone who has an alright knowledge of Java and wants to take it to the next level.

Write Code as a Professional Developer

Excellent read for anyone who already know how to program and want to learn Best Practices

Every Developer should read this

Perfect book for anyone transitioning into the mid/mid-senior developer level

Great preparation for interviews

Great book and probably the best way to practice for interview. Some really good information on how to perform an interview. Code Example in Java