In the earlier chapters, we’ve seen a lot of the most important Git features and concepts. We’ve learned about commits, branches, pull requests, and merging. Using those concepts, you can already accomplish almost anything in Git. Only one small problem, though: we’ve only used the Terminal or Console window. In this chapter, you won’t learn any new concept or feature; you will just learn how to apply what you already know with style ☺
First, we’re going to investigate the default tools that come with Git, then learn more about IDEs that integrate Git, and lastly look at some specialized tools specially made for Git.
Default tools
If you’ve followed the installation steps from the Chapter 2, you already have those tools installed on your computer. If not, you can easily get them on our habitual software store. These default tools are shipped with Git to provide users very simple GUIs to browse their repositories and prepare their commits. They are available for almost any Operating Systems, so don’t worry, they are available to you. They are presented in this book for historical reasons and because they come built-in into Git.
Committing: git-gui
The first tool we are going to see is called git-gui and it’s a graphical committing interface for Git. You will use it to commit your project and review proposed changes. You can find more information about it on https://git-scm.com/docs/git-gui.
Top left is a list of edited files that have not been staged yet.
Bottom left is a list of files that have been staged.
Top right is a diff view.
Bottom right is a commit message text area.
And since we haven’t changed anything in our project, everything is empty. So, let’s mess up our project with additional commits.
The first input area is the most important: the name of your new branch. Name the branch “separate-code-and-styles.”
The second input is a choice input where you have to select where you are going to create the branch from. In our situation, we are going to create a new branch from our local master branch; so choose “local branch” and select “master.”
The third part are the options, which I recommend keeping the default options. With the default options, Git will fetch the latest commits on the remote (tracking) branch and then check out the new branch.
Now that we are in the correct branch, we can work on our commit. Remember our golden rule when discussing Git workflow? Each commit must have the resolution of an issue as goal. I’ll let you create that issue.
EXERCISE: CREATE AN ISSUE
Go to GitHub issues.
Create an issue called “Separate code and styles.”
Take note of the issue number.
An empty file icon for a new file (never been committed)
A file icon for a modified file (has been part of a commit before)
A “?” icon for a deleted file (has been part of a commit before)
See? Way quicker than typing commands!
Now with our files staged and our commit message written, we are ready to commit. Just click the “Commit” button near the commit message box. After you do so, Git GUI comes back to its normal, empty state. We’ve committed from the graphical tool!
Since you are my best student (don’t tell the others), I’ll let you make another commit in our branch.
EXERCISE: MAKE ANOTHER COMMIT
Open README.md.
Add this line at the end of the file: “License: MIT.”
Create a new file called LICENSE.
Copy the license text from https://choosealicense.com/licenses/mit/ into the LICENSE file.
Stage both files.
Commit with the message “Add MIT license.”
It’s a straightforward interface; you just have to select the branch you want to push and the location where you want to push it.
The current branch is selected by default, so we don’t have to change anything. The second section is the destination selection dropdown; and again, we don’t have to change anything because we only have one remote repository. Ignore the options for now; we will see them in a later chapter.
Tip
If you don’t want to write your password each time you push, you can cache it or use an SSL authentication; all of this is explained in later chapters.
EXERCISE: CREATE A PULL REQUEST
Follow the link you got after pushing.
Create a pull request with this description: “Fix #10” (replace the number with the issue number you created earlier).
Merge the PR.
Rejoice.
And that’s how you commit with Git GUI! Simple, right? And very quick too. It’s a great tool that can save you a lot of time when reviewing commits. Talking about commits, let’s see the other default tool!
Browsing: gitk
In the previous section, we talked a lot about creating and pushing commits. Now, we are going to visualize those commits in their natural habitat: the repository. gitk is a simple tool to have a simple visual of your project history. You can think of it as an overpowered “git log” command. More documentation about gitk can be found on https://git-scm.com/docs/gitk.
And that’s it for gitk, the default browsing tool of Git! Since you can commit and browse with the default graphical tools now, it’s time to present you to other tools.
IDE tools
As we saw in the previous section, committing with a graphical tool is very fast compared to typing in the console. But there still is a problem: you must leave your Integrated Development Environment to use them. Wouldn’t it be nice if you could use the graphical tools directly from your editor?
It’s possible with a lot of modern editors. I will present you to two popular IDEs that have Git integrated so you can use them for your future development. And if you don’t want to use them or you are already in love with your current editor, chances are that your IDE also have integrated Git tools or plugins if it’s modern enough. Each IDE has its own interface and user experience, so I won’t go into detail in this section. I just want to show to what features are available.
Visual Studio Code
It has the same interface as any other IDE but with a little bonus: you can see traces of Git here and there. First, if you change a tracked file (README.md here), the edited part is highlighted; no need to execute git diff anymore!
And at the bottom left of the window, you have the current branch name; if you click it, you can select the branch you want to navigate to or create a new branch. If you have unstaged files, there will be a little “∗” sign near your branch name and an “M” icon near the concerned file names. If you have staged push uncommitted files, you have a “+” sign.
This view looks and works very much like git-gui, so I’ll let you discover it yourself!
Atom
It has the same Git features as Visual Studio Code but with a little twist: you can link your GitHub account to it and create PR directly from the editor! Again, I’ll let you discover.
Specialized tools
We saw the default Git tools and some IDEs that have Git integrated. Now, let’s see some tools specially developed for Git.
GitHub Desktop
GitKraken
Again, the interface is the same as the others, but what distinguish GitKraken is its beauty: it’s insanely gorgeous!
Summary
This chapter was fun, wasn’t it? We learn a lot about how to use a graphical tool to make commits and browse them. We also discovered a ton of new tools that are available to us, be it integrated into an IDE or a specialized tool. And how can we forget about our good old default tool?!
You may ask yourself why not use the graphical tool from the very beginning? It’s because using a tool without knowing the concepts behind them is counterproductive and a waste of time. Trust me, learning to use the Terminal was worth it! Talking about terminals, let’s get back to it for some more advanced Git commands!