Git

Git is a popular open-source tool for code versioning.

Intro

https://ohmygit.org/

Installation

There are also many GUIs and extensions/plugins for various IDEs. We will keep using the command line interface in a terminal – I think it is the best way to fully understand how git works and how it should be used.

Basic concepts

First use – getting an existing project

All other commands must be run inside a project, i.e., in a directory that contains .git/ (e.g. git clone creates this).

Workflow for programmers

Synchronization between local and remote repositories:

Working with branches:

Metadata configuration (enough to do it just once; --global applies the settings for all projects, stored in the user‘s home directory; --local changes the settings only in the current project):

Adding changes:

NEVER use the commands git add . and git commit -a (git commit --all)!!! Always commit only the changes you really want to add to git. Furthermore, commits should be divided systematically and reasonably „large“.

Hint: It is better to make multiple smaller commits than one big commit, because it is much easier to recombine the commits after the fact than splitting a commit into multiple commits.

.gitignore

The .gitignore file allows to ignore specific files and directories that we never want to commit. Such files are not shown in git status and they will not be staged by the git add command (unless we explicitly force it).

In general, the following files/directories should be ignored:

Next concepts

And a lot more, see https://git-scm.com/docs/gitglossary

Merge and rebase

Mergetool

git mergetool provides an interface between git and a text editor for resolving conflicts. Git subsequently opens the editor with files with a conflict. For each file it opens up a window with typically 4 versions:

The supported tools can be shown by running git mergetool --tool-help.

Resources

Rebase:

Workflow, best practices:

Cheat Sheet:

Git Cheat Sheet