No description
Find a file
2021-06-21 12:07:25 +02:00
gitcrux_cheatsheet.svg first commit 2021-03-10 14:45:02 +01:00
LICENSE add license file 2021-06-21 12:07:25 +02:00
README.md add diagram in readme 2021-03-10 14:47:46 +01:00

The crux of Git

Git is:

  • a backup system
  • which targets source code

Git is not:

  • a backup repository for large binary files
  • homeomorphic endofunctors mapping submanifolds of a Hilbert space

Create a Git repository from scratch:

mkdir mysoft
cd mysoft
git init
git config user.name "Johann Dreo"
git config user.email johann.dreo@pasteur.fr

Basics

Commits

A Git repository is an history of incremental commits.

git log
echo "My soft" > README.md
git status
git add README.md
git commit
git status
git log

Canonic commit message format:

<type>[scope]: short title

Summary of changes.
With emphasis on the "why?".

[metadata]

Common types: fix, feat, docs, style, refactor, test.

See: https://www.conventionalcommits.org/en/v1.0.0/

Patches

echo "is awesome!" >> README.md
git status
git diff
git add README.md
git commit -v
git log

Branches

git checkout -b "fix/ortho"
vim README.md
git add README.md
git commit -v
gitk --all .

Merge

git checkout master
git merge fix/ortho
git log
gitk --all .

Remotes

Copy of the repository

Remote repository are backup of your local one

  • elsewhere in your file system,
  • on a server somewhere on the network (e.g. via https, ssh),
  • hosted by services provider (e.g. github, gitlab)
cd ..
mkdir myremote
cd myremote
git clone ../mysoft
cd mysfot
gitk --all .

pull

You can get several commits at once from a remote repository with a pull:

cd ../../mysoft
echo "Check it out." >> README.md
cd ../myremote/mysoft
git pull ../../mysoft

Named remotes

You can give a name to a remote.

cd ../../mysoft
git remote add there ../myremote/mysoft
git pull there master

Remote Servers

If you own a privileged access to a remote on a server (e.g. gitolite on LAN, github or gitlab on internet, etc.), you can backup a set of commits with a push.

Workflow summary

Classical workflow for working with others: 0. pull

  1. checkout -b feat/myfeat
  2. Edit, status, diff, commit -a -v, stash.
  3. pull origin master
  4. checkout master
  5. merge feat/myfeat
  6. push
  7. Pull request
    • just send an e-mail, or
    • send a patch, or
    • on the issue tracker.

Gitcrux workflow diagram

Nice Git features

  • Automatic merge.
  • Conflict detections.
  • Faulty commit search (see bisect).