Skip to content

Git

Learning Git

The following three videos by David Mahler are a decent introduction to Git version control system and teach you the key concepts of Git in a illustrative way. Runtime is 30m each for a total of 1.5h. I wish I started to learn Git this way back then. 😜

Core Concepts
Branching and Merging
Remotes

In addition, the below book, the visual overview of the most used Git commands and lastly the visual playground below are helpful too. And.. Git's very good documentation as the one source of truth as reference.

Configuration files

There are a number of configuration files that git offers and that let user customize their git experience in great depth. As usual great powers comes with great responsibility. 😉 Not all configuration files and options are mentioned here, there are many more.

First Time Git setup

This step is really important as you set some default behaviour and especially you have to set your identity! This last step - configuring your identity - is neglected very often. Please, don't. Now go and read first time git setup!

Keep in mind that you just set your global identity. Almost every configuration key is also changeable on repo level. This means while your global identity may be "MrCool cool@test.com", you can still have another identity on a per repo basis, i.e. when implementing stuff for work. You can set your identity within the repo directory by issuing:

git config user.name  "Max Mustermann"
git config user.email max.mustermann@example.com

As you can see, the same command is run, but --global is left out. Now this local setting can be found in the config file of the repo, .git/config. While the global configuration file is found at ~/.gitconfig.

Unsure what your identity is in the current repo? Just run git config user.name or git config user.email respectively.

Repo-local Configuration Files

.gitignore - Specifies intentionally untracked files to ignore

A gitignore file specifies intentionally untracked files that Git should ignore, see man gitignore or in the git-book. This is valuable if you have some local temporary files, that should not get committed except if forced. Other examples may include a vendor library that is used that is versioned somewhere else and gets installed as a dependency.

.gitattributes - Defining attributes per path

A gitattributes file is a simple text file that gives attributes to pathnames, i.e. end of line style, see man gitattributes or in the git-book.

Articles

The Thing About Git (15' read)

Often beginners find it oddly strange that there is an index/staging area in Git and are not aware for what this thing can be used. Other VCS do not have this. Nevertheless it's not an addition just to make Git more complicated and to bother the developers. The "Tangled Working Copy Problem" illustrates why this concept makes sense and how you should use it to your favor. There's one important option tot git add that most beginners overlook (and tutorials almost never teach you), e.g. --patch or -p

Try the following form of adding files to the index next you have to do that and see what happens!
git add --patch somepathspec or git add -p somepathspec


Last update: October 9, 2023