Graphical interfaces

You have learned how to use Git on the command line. The previous section told you how to customize and configure it to make it even more effective. But the terminal is not the end. There are other kinds of environments you can use to manage Git repositories. Sometimes, a visual representation is what you need.

Now, we'll take a short look at the various kinds of user-centered graphical tools for Git; the tour of Git administrative tools is left for the next chapter, Chapter 11, Git Administration.

Types of graphical tools

Different tools and interfaces are tailored for different workflows. Some tools expose only a selected subset of the Git functionality, or encourage a specific way of working with version control.

To be able to make an informed choice selecting a graphical tool for Git, you need to know what types of operations the different types of tools do support. Note that one tool can support more than one type of uses.

First there is a graphical history viewer. You can think of it as a powerful GUI over git log. This is the tool to be used when you are trying to find something that happened in the past, or you are visualizing and browsing your project's history and the layout of branches. Such tools usually accept revision selection command-line options, such a s--all. Command-line Git has git log --graph and less used git show-branch that use ASCII-art to show the history.

A similar tool is graphical blame, showing the line-wise history of a file. For each line, it can show when that line was created and when it was moved or copied to the current place. You can examine the details of each of the commits shown, and usually browse through the history of the lines in a file. Other tools with similar applications, namely examining the evolution of the line range (git log -L) and the so called pickaxe search (git log -S) does not have many GUIs.

Next, there are commit tools meant primarily to craft (and amend) commits, though usually they also include some kind of worktree management (for example ignoring files and switching branches) and management of remotes. Such tools would usually show unstaged and staged changes, allowing you to move files between these states . Some of those tools even allow to stage and unstage individual chunks of changes, like interactive versions of git add, git reset, and so on. A graphical version of an interactive add is described in Chapter 4, Managing Your Worktree, and mentioned in Chapter 3, Developing with Git.

Then, we have file manager integration (or graphical shell integration). These plugins usually show the status of the file in Git (tracked/untracked/ignored) using icon overlays. They can offer a context menu for a repository, directory, and file, often with accompanying keyboard shortcuts. They may also bring drag and drop support.

Programmer editors and integrated development environments (IDEs) often offer support for IDE integration with Git (or version control in general). These offer repository management (as a part of team project management), make it possible to perform Git operations directly from the IDE, show the status of the current file and the repository, and perhaps even annotate the view of the file with version control information. They often include the commit tool, remote management, the history viewer, and the diff viewer.

Git repository's hosting sites often offer workflow-oriented desktop clients. These mostly focus on a curated set of commonly used features that work well together in the flow. They automate common Git tasks. They are often designed to highlight their service, offering extra features and integration, but they will work with any repository hosted anywhere.

Graphical diff and merge tools

Graphical diff tools and graphical merge tools are somewhat special case. In these categories, Git includes the commands for integration with third-party graphical tools, namely, git difftool and git mergetool. These tools would then be called from the Git repository. Note that this is different from the external diff or diff merge drivers, which replace ordinary git diff or augment it.

Although Git has an internal implementation of diff and a mechanism for merge conflict resolutions (see Chapter 7, Merging Changes Together), you can use an external graphical diff tool instead. These are often used to show the differences better (usually, as a side-by-side diff, possibly with refinements), and help resolve a merge (often with a three-pane interface).

Configuring the graphical diff tool, or the graphical merge tool, takes a number of custom settings. To tell which tool to use for diff and merge, respectively, you can set up diff.tool and merge.tool, respectively . Without setting for example "merge.tool" the "git mergetool" command would print the information on how to configure it, and will attempt to run one of predefined tools:

$ git mergetool

This message is displayed because 'merge.tool' is not configured.
See 'git mergetool --tool-help' or 'git help config' for more details.
'git mergetool' will now attempt to use one of the following tools:
tortoisemerge emerge vimdiff
No files need merging

Running git mergetool --tool-help will show all the available tools, including those that are not installed. In case the tool you use is not in $PATH, or it has a wrong version of the tool, you can use mergetool.<tool>.path to set or override the path for the given tool:

$ git mergetool --tool-help
'git mergetool --tool=<tool>' may be set to one of the following:
                vimdiff
                [...]

The following tools are valid, but not currently available:
                araxis
                […]

Some of the tools listed above only work in a windowed
environment. If run in a terminal-only session, they will fail.

If there is no built-in support for your tool, you can still use it; you just need to configure it. The mergetool.<tool>.cmd configuration variable specifies how to run the command, while mergetool.<tool>.trustExitCode tells Git whether the exit code of that program indicates a successful merge resolution or not. The relevant fragment of the configuration file (for a graphical merge tool named extMerge) could look as follows:

[merge]
    tool = extMerge
[mergetool "extMerge"]
    cmd = extMerge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"

Graphical interface examples

In this section, you will be presented with a selection of tools around Git that you could use, or that might prompt you to research further. A nice way to start such a research is to list some selected GUI clients.

There are two visual tools that are a part of Git and are usually installed with it, namely gitk and git-gui. They are written in Tcl/Tk. Gitk is a graphical history viewer, while git gui is a commit tool; there is also git gui blame, a visually interactive line-history browser. These tools are interconnected, for example, browsing history from git gui opens gitk.

Visual tools do not need to use the graphical environment. There is tig (Text Interface for Git), a nurses-based text-mode interface, which functions as a repository browser and a commit tool, and can act as a Git pager.

There is git cola developed in Python and available for all the operating systems, which includes commit tools and remotes management, and also a diff viewer. Then, there is the simple and colorful Gitg tool for GNOME; you will get a graphical history viewer, diff viewer, and file browser.

One of the more popular open-source GUI tools for MacOS is GitX. There are a lot of forks of this tool; one of the more interesting ones is Gitbox. It features both the history viewer and commit tools.

For MS Windows, there is TortoiseGit and git-cheetah, both of which offer integration into the Windows context menu, so you can perform Git commands inside Windows Explorer (the file manager integration and shell interface).

Both GitHub Inc. and Atlassian released a desktop GUI tool that you can easily use with your GitHub or Bitbucket repository, respectively, but it is not limited to it. Both GitHub Client and SourceTree feature repository management in addition to other common facilities.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset