Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

git

Track every change of code and config, work on branches, and share work through remotes like GitHub — the base of CI/CD and GitOps.

Niveau
DevSecOps-service
Groep
Git en CI/CD
Root nodig
Nee
Pakket
git

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

git keeps the full history of a project in a local repository (.git/). You change files, stage them (git add), and save a commit. Branches let you work on a feature without touching main; a pull request merges it after review and CI. A remote (origin) is the shared copy on GitHub, GitLab or Azure Repos.

In DevSecOps, Git is the source of truth: app code, Dockerfiles, Terraform, Kubernetes YAML and pipelines all live in Git, and every change goes through review. Signed commits and secret scanning protect it.

Zo schrijf je het

git COMMAND [OPTIONS] [ARGS]

Belangrijkste delen

Daily commands

clone URL
Copy a remote repository.
status
What changed, what is staged.
add FILE / add -p
Stage changes (by parts with -p).
commit -m MSG
Save a commit.
log --oneline --graph
Show history.
diff [--staged]
Show changes.
switch -c BRANCH / switch BRANCH
Create / change branch.
pull / fetch / push
Get / send changes.
merge BRANCH
Join a branch into the current one.
rebase BRANCH
Replay your commits on top of another branch.
restore FILE / restore --staged FILE
Undo changes / unstage.
revert COMMIT
New commit that undoes an old one (safe on shared branches).
reset --soft|--hard COMMIT
Move the branch (hard deletes work!).
stash / stash pop
Put work aside and bring it back.
tag -s v1.4.0
Make a (signed) tag.
blame FILE / bisect
Who changed a line / find the bad commit.
remote -v / remote add NAME URL
Manage remotes.
cherry-pick COMMIT
Copy one commit to this branch.

Opties 9

Meest gebruikt

Useful settings and flags

config --global user.name/user.email
Your identity.
config --global init.defaultBranch main
Default branch name.
config --global pull.rebase true
Rebase on pull.
config --global commit.gpgsign true
Sign every commit.
config --global gpg.format ssh
Sign with an SSH key.
-c KEY=VAL
Set config for one command.
--amend
Change the last commit (only before push).
--force-with-lease
Safer force push.
--depth 1
Shallow clone (CI).

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Set up your identity and signing

    git config --global user.name "s0sta"
    git config --global user.email "76218642+s0sta@users.noreply.github.com"
    git config --global gpg.format ssh
    git config --global user.signingkey ~/.ssh/id_ed25519.pub
    git config --global commit.gpgsign true
  2. 2Start work on a feature branch

    git clone git@github.com:s0sta/platform.git && cd platform
    git switch -c feat/add-health-check
    vim app/health.py
    git add -p
    git commit -m "Add /health endpoint"
    git push -u origin feat/add-health-check
  3. 3See what happened

    git status
    git log --oneline --graph --decorate -15
    git diff main...feat/add-health-check --stat
  4. 4Update your branch with main

    git fetch origin
    git rebase origin/main
    git push --force-with-lease
  5. 5Undo safely

    git restore app/config.py
    git restore --staged app/config.py
    git revert 3f2a91c
    git commit --amend -m "Better message"
  6. 6Put work aside

    git stash push -m "half done"
    git switch main && git pull
    git switch - && git stash pop
  7. 7Tag a release

    git tag -s v1.4.0 -m "Shop 1.4.0"
    git push origin v1.4.0
    git tag -v v1.4.0
  8. 8Find the commit that broke something

    git bisect start
    git bisect bad HEAD
    git bisect good v1.3.0
    git bisect reset
  9. 9Remove a secret that was committed

    git rm --cached .env && echo ".env" >> .gitignore
    git commit -m "Remove .env from repo"

    The secret is still in the history: rotate it first, then clean history with git filter-repo.

  10. 10Stop secrets before they are committed

    cat .git/hooks/pre-commit
    #!/bin/sh
    exec gitleaks protect --staged --redact
    chmod +x .git/hooks/pre-commit

Let op

  • Never push --force to main; protect main with branch rules and required reviews.
  • git reset --hard and git clean -fd delete work you did not commit.
  • A secret in any commit is leaked — rotate it, do not only delete the file.

Bestanden

~/.gitconfig
Your global settings.
.git/
The repository data.
.gitignore
Files Git should not track.
.git/hooks/
Local hooks (pre-commit, commit-msg).

Tips om te onthouden

  • Small commits with clear messages ("Add …", "Fix …") make review and rollback easy.
  • Use pre-commit framework hooks: gitleaks, terraform fmt, yamllint.

Exitcodes

0Success.
1Error or conflict.
128Fatal error (not a repository, bad argument).

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man git