2.6.3. Online Git tutorial#
To become more familiar with the most basic Git commands, and the effect that will have on the version tree in your Git repository, we advise you to follow (parts of) the interactive tutorials on https://learngitbranching.js.org/. This website introduces you Git commands, as you would type them in the terminal, and visualizes the resulting version tree.
The tutorials are grouped into two sections, Main with the basic commands for local Git usage, and Remote with the additional Git commands when working with a remote server (such as gitlab).
Exercise 2.88
Go to https://learngitbranching.js.org/, we recommend that you follow at least these levels[1]:
All levels of `Introduction Sequenceâ in the Main section.
All levels of `Ramping Upâ in the Main section.
All levels of `Push & Pullâ in the Remote section.
All levels of `To Origin And Beyondâ in the Remote section. Of course, feel free to also go through the remaining tutorial levels, but these should help you get started for the remainder of this lab assignment.
Finally, it can also be convenient to visualize the Git commit graph of a repository that you were working on in the terminal, similar to how it was shown in the online tutorial. This can help you study the effect of a particular Git command, or fix issues that you will undoubtedly run into when using Git, such as accidentally committing in DETACHED HEAD mode.
The git log command can show information of the recent commits, but does not by default show you the actual graph structure.
As was explained at the end of the Git lecture slides, it is actually possible to give some extra options to git log to make it display more information.
If you type git log --graph --decorate --all you should get a more detailed view of the graph, the branch names, and the HEAD, right in the terminal.
Rather than remembering this long command, and always retyping it, we can define a shorthand in Git, a so called alias.
Exercise 2.89
Configure once on your computer a global alias for a graphical log that weâll call glog:
$ git config --global alias.glog "log --graph --decorate --all"
Now you can scroll through the Git log with a graphical representation of the commit graph on the left in the terminal by typing only git glog.
Since this is a globally configured alias, this will work on any Git repository on your computer.
Exercise 2.90
In the directory of your local Git repository from before, try typing
$ git glog
You should see a (not too exciting) log with some coloured indications of the HEAD and branch(es).