Skip to content

πŸ™ Git Cheatsheet

πŸ”§ Configuratie en instellingen

Globale instellingen:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main

Voorbeeld .gitconfig:

# This is Git's per-user configuration file.
[user]
        name = Piet
        email = Paaltjes@gmail.com
[init]
        defaultBranch = main
[format]
        pretty = %h %ad | %s%d [%an]
[log]
        date = short
[alias]
        st = status -s
        ll = log --pretty=format:\"%h %s\" --graph
        lll = log --pretty=format:\"%h - %an, %ar : %s\"
[color]
  ui = true
  branch = true
  diff = true
  status = true
#[push]
#  default = simple
[credential]
        helper = cache --timeout=36000
[core]
  editor = vim

πŸ™ˆ .gitignore

hosts
ansible.cfg
collections/**
!collections/requirements.yml
collections/ansible_collections
ansible-navigator.log
*-artifact-*
.ssh

⏩ Handige aliassen

Snelle status en logs:

git config --global alias.st 'status -s'
git config --global alias.ll 'log --pretty=format:"%h %s" --graph'
git config --global alias.lll 'log --pretty=format:"%h - %an, %ar : %s"'

Korte commando’s:

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit

Logweergave en datumnotatie:

git config --global format.pretty '%h %ad | %s%d [%an]'
git config --global log.date short

πŸ“œ Logs en geschiedenis

Voorbeelden:

git log --pretty=format:"%h %ad | %s%d [%an]" --date=short
git log --pretty=oneline
git log --pretty=format:"%h - %an, %ar : %s"
git log --pretty=format:"%h %s" --graph

Filters:

git log --oneline --max-count=2
git log --oneline --since="5 minutes ago"
git log --oneline --until="5 minutes ago"
git log --oneline --author="Your Name"
git log --oneline --all
git log --all --pretty=format:"%h %cd %s (%an)" --since="7 days ago"
git log -S Zoekterm

♻️ Herstellen en terugdraaien

Bestand uit specifieke commit halen:

git show <commit>:pad/naar/bestand
git checkout <commit> -- pad/naar/bestand
git add pad/naar/bestand
git commit -m "Rollback van <bestand> naar <commit>"

Revert naar oudere staat (meerdere commits terugdraaien):

git revert -n HEAD~3..HEAD
git add .
git commit -m "Starting over from 3 commits back"

Laatste commit overschrijven (bericht of inhoud):

git commit --amend -m "Nieuw bericht"

Bestand unstagen (na git add):

git restore --staged README.md
# Inhoud blijft ongewijzigd; staging verdwijnt

Wijzigingen aan bestand verwerpen (niet gestaged):

git restore README.md

Checkout van commit:

# Tijdelijk (detached HEAD)
git checkout <commit-sha>

# Nieuwe branch vanaf commit
git checkout -b nieuwe-branch <commit-sha>

🌿 Branches

Remote branch uitchecken:

git checkout -b lokale-naam origin/remote-branch-naam

Lokale branch aanmaken:

git switch -c MyNewBranch

Lokale branch verwijderen:

git branch -d pipo

Branches tonen en opschonen:

git pull -p          # prune lokale referenties naar verwijderde remote branches
git branch -a        # lokale + remote
git branch -r        # alleen remote

Clonen en basis-remote acties:

git clone https://github.com/schacon/ticgit
cd ticgit
git fetch
git pull
git push
git switch -c MyNewBranch

Branch naar remote pushen:

git push -u origin MyNewBranch

Remote branch verwijderen en prunen:

git push origin :MyNewBranch
# of
git push origin -d MyNewBranch
git pull -p

Remote inspecteren:

git remote show origin
git branch -a
git branch -r

🏷️ Tags

Tags tonen:

git tag
git tag -n

Annotated tag maken (optioneel op specifieke commit):

git tag -a v1.0 -m "my version 1.0"
git tag -a v1.2 9fceb02 -m "Message here"

Tag pushen:

git push origin v1.0
git push origin --tags   # alle tags in één keer

Lightweight tags:

git tag v1.0.1
git show v1.0.1

Remote tags bekijken en ophalen:

git ls-remote --tags origin
git fetch                 # haalt ook tags op

Tags verwijderen (lokaal en remote):

git tag -d v1.4-lw
git push origin --delete v1.4-lw

Uitchecken vanaf tag (nieuwe branch):

git fetch
git checkout -b Feature/v1 v1.0.1

πŸ“¦ Submodules

Submodule toevoegen:

git clone git@github.com:zilux/template_play.git
cd template_play/
mkdir -p collections/ansible_collections
git submodule add git@github.com:zilux/template_collection.git collections/ansible_collect

Submodules clonen en initialiseren:

git clone https://github.com/chaconinc/MainProject
cd MainProject
git submodule init
git submodule update

Alles in één keer (recurse):

git clone --recurse-submodules https://github.com/chaconinc/MainProject

🏠 HOME πŸ” Top