11  Graphical User Interfaces


In this chapter, we will give an introduction to Graphical User Interfaces (GUIs) for Git. We will showcase two different, commonly used GUIs, including GitHub Desktop and GitKraken as well as the Git integration in RStudio. Finally, we will discuss specific use cases where a graphical user interface makes Git operations easier and less error-prone compared to the command-line.

Learning Objectives

💡 You understand the benefits of Git GUIs compared to the command line
💡 You can name at least two Git operations that can be considered easier in a GUI compared to the command line
💡 You try out different GUIs and become familiar with their features
💡 You know how to manage branches in a GUI

11.1 Introduction to Git GUIs

Graphical User Interfaces (GUIs) offer a more user-friendly way to work with Git compared to the command-line, using visual buttons and indicators instead of text commands. They show your project’s history, branches, and changes in a more colorful and easy-to-understand manner.

GUIs make Git appear less scary and more accessible to everyone, helping you manage your code, without the hassle of remembering complex text-based commands in the command-line. While Git GUIs offer a user-friendly approach to version control, they come with a few limitations. One notable drawback is their reduced flexibility compared to the command-line interface. GUIs are designed to simplify common tasks, but more advanced or customized operations may be challenging to perform within a graphical environment. Despite their user-friendly design, understanding the underlying Git concepts and the specific workflow of a GUI is still very important.

As this book primarily emphasizes learning Git through the command line interface, this chapter will only feature a short introduction, but not extensive tutorials for GUI tools.

11.3 Use cases for Git GUIs

You can perform a wide range of basic and advanced Git operations with GUIs. Here, we present a few Git use cases where the use of a GUI can be particularly helpful as compared to doing the same thing from the command-line.

11.3.1 Partial commits

One useful feature of Git GUIs is the ability to easily commit only specific parts or “hunks” of code from within a file. This is particularly handy when you’ve made changes to different parts of a file and want to commit them separately to group related changes together and keep a clean commit history. With a Git GUI, you can easily select the lines or blocks of code you want to include in a commit, stage them, and then commit just those changes.

For example, to do this in GitKraken, change a file, then click on your last commit in the GitKraken GUI (see Figure 11.5). You will see a list of unstaged files with changes. After you click on one, you will see your additions highlighted green and your deletions highlighted red. If you hover over the changed lines you will see the option to “Stage this Line”. To stage multiple lines at the same time, highlight the ones you want to stage, do a right-click and select “Stage selected lines”. You can also stage the whole file or “hunk” and unstage specific changes.

Figure 11.5: Screenshot of Rstudio. Showing staging an example file.

In Git, a “hunk” refers to a distinct block of code changes within a file. It represents a cohesive set of added, modified, or deleted lines in a specific location. Git automatically divides changes into hunks to facilitate easier review, selective staging, and conflict resolution during version control operations.

You can also create a partial commit in GitHub Desktop. For details, see the GitHub Desktop documentation.

11.3.2 Merge conflict resolution

Git GUIs make resolving merge conflicts more intuitive. When conflicts arise due to incompatible changes made in different branches, a GUI helps you identify conflicting lines side by side. You can then select which changes to keep, discard, or modify. The graphical representation simplifies the process.

To merge two branches in GitKraken, you can either drag and drop one branch onto another branch or use the right-click menu of the branch you want to merge in. If a merge conflict occurs you will see a list of conflicted files. When you click on a file, it will show you a side-by-side comparison of the conflicting changes, allowing you to choose which lines to keep. After resolving all conflicts, you can continue the merge process by completing the merge commit.

Figure 11.6: Screenshot of Gitkraken. Showing an example merge conflict.

11.4 Git Integration in RStudio

Even though it is not a complete GUI, RStudio Desktop, the most popular development environment for programming, offers Git integration to simplify version control within your projects.

When opening a new RStudio project, you can choose to “Checkout a project from a version control project”. After choosing this, you have the option to clone a Git repository, for example from Github. RStudio will then download the files and you can start to edit them in RStudio.

Figure 11.7: Screenshot of Rstudio. Showing the options for loading a repository.

After cloning a remote repository or opening a local Git repository folder, you can do things like committing, pushing or switching branches using buttons in Rstudio, instead of using the command line. The Git tab within the upper right panel enables you to stage, commit, push and pull changes. The branches tab in the Git pane displays a list of available branches, making it straightforward to switch between them.

Figure 11.8: Screenshot of Rstudio. Showing an example repository.

Clicking “Commit” will open up a window, where you see your changes marked with colors. You also easily write commit message and have the option to amend your last command. It is also possible to stage specific lines.

Figure 11.9: Screenshot of Rstudio. Showing an example commit.

For a more comprehensive tutorial on using Git in Rstudio you can check out the “Happy Git and GitHub for the useR” by Jenny Bryan.

You should keep in mind that while the RStudio GUI simplifies many Git tasks, it lacks the flexibility and customization of using the command line. But considering you can also open a command line tab in RStudio, the GUI might be a help in your workflow, if you work on a project and track it using Git.

11.5 Acknowledgements & further reading

Authors Title Website License Source
Bryan (2023) Happy Git and GitHub for the useR CC BY-NC 4.0
GitHub (2023) GitHub Docs CC BY-NC 4.0