Geavanceerd
Zoeken inInstallatiegidsen
Zo zoek je
  • Plak een foutmelding tussen aanhalingstekens, bijv. "permission denied", om de oplossingstabel te vinden.
  • Kies een gebied en een deel van de gids (installeren, eerste instellingen, dagelijks gebruik, beveiliging, oplossingen) om direct naar de juiste stap te gaan.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Gids 2Git · Version control

Install and set up Git

Git keeps the full history of your code, scripts and configuration. Every DevOps job starts with Git: pipelines, GitOps and infrastructure as code all read from a Git repository. This guide installs Git on RHEL and Ubuntu, makes the first settings (name, email, default branch, SSH key, signed commits), shows the daily commands and gives fixes for the most common errors.

  • 10 Lessen
  • 8 Commando's

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

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

2.1

Know it before you install

Git is a program on your computer, not a server. Your repository lives in the .git folder of your project. GitHub, GitLab and Bitbucket are servers that keep a shared copy (the remote).

ItemValue
Packagegit (RHEL: git or the small git-core)
Servicenone (Git is a command-line tool)
Your settings~/.gitconfig (global), .git/config (one repository)
System settings/etc/gitconfig
Ignore rules.gitignore in the project, ~/.config/git/ignore for all projects
Network ports22 (SSH remotes) or 443 (HTTPS remotes)

What you need:

  • Any Linux, macOS or Windows machine.
  • An account on GitHub or GitLab if you want to push code.

Commando's in deze les

2.2

Install on RHEL, Rocky, Alma and Fedora

dnf -y install git
git --version
git version 2.47.1

Notitie

RHEL also has git-all (with the GUI tools and git svn). You do not need it on servers.

2.3

Install on Ubuntu and Debian

apt-get update
apt-get install -y git
git --version

Op het werk

Ubuntu LTS can have an older Git. For the newest stable version add the Git maintainers' PPA: add-apt-repository ppa:git-core/ppa, then apt-get install -y git.

Commando's in deze les

2.4

First configuration: the settings to make first

Set these once on every new machine. Git writes your name and email into every commit.

git config --global user.name "Your Name"
git config --global user.email "ID+USERNAME@users.noreply.github.com"
git config --global init.defaultBranch main
git config --global pull.rebase false
git config --global fetch.prune true
git config --global core.autocrlf input
git config --global core.editor "vim"
git config --global --list
SettingWhy
user.name, user.emailWho made the commit. Use the GitHub noreply address to keep your real email private.
init.defaultBranch mainNew repositories start on main, like GitHub and GitLab.
pull.rebase falsegit pull merges and does not ask every time (true = rebase, also fine — choose one for the team).
fetch.prune trueRemote branches that were deleted on the server disappear locally too.
core.autocrlf inputWindows line endings (CRLF) are changed to LF when you commit. On Windows use true.

Add a global ignore file for files that never belong in Git:

~/.config/git/ignore
.env
*.pem
*.key
.DS_Store
.idea/
.vscode/
__pycache__/
*.tfstate*
.terraform/

Commando's in deze les

2.5

Connect to GitHub or GitLab with an SSH key

SSH keys are safer and easier than passwords. Make one key per computer, protect it with a passphrase and add the public key to your account.

ssh-keygen -t ed25519 -C "laptop-2026"
cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... laptop-2026
ssh -T git@github.com
Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.

GitHub: Settings → SSH and GPG keys → New SSH key. GitLab: Preferences → SSH Keys.

Sign your commits with the same key, so GitHub shows them as Verified (add the key a second time as a Signing key):

git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true
git log --show-signature -1

2.6

Daily use: the commands and the real uses

Start or copy a project:

git clone git@github.com:USERNAME/my-project.git
cd my-project
git status

The daily loop — branch, change, commit, push, open a pull request:

git switch -c fix-backup-script
git add backup.sh
git commit -m "Fix the backup path"
git push -u origin fix-backup-script
git switch main
git pull

Look at history and changes:

git log --oneline --graph --decorate -15
git diff
git diff --staged
git show HEAD
git blame backup.sh

Undo safely:

git restore file.txt
git restore --staged file.txt
git commit --amend
git revert a1b2c3d
git stash && git stash pop

Real uses at work:

  • Keep server configs, scripts and Ansible/Terraform code in Git, with review in pull requests.
  • GitOps: Argo CD or Flux deploy what is on the main branch.
  • Find when a bug came in: git bisect. Find a lost commit: git reflog.

Commando's in deze les

2.7

Make it safe

Security checklist:

  • Never commit secrets (.env, keys, passwords, *.tfstate). Use the global ignore file above.
  • Scan before you push: gitleaks git (or as a pre-commit hook).
  • An SSH key with a passphrase, one key per device; delete keys of lost devices on GitHub.
  • Signed commits (commit.gpgsign true) and branch protection on main (review + green CI before merge).
  • Use HTTPS tokens only with short expiry and the smallest scope.

Let op

If you committed a secret, deleting the file in a new commit is not enough — it is still in the history. First rotate the secret (make a new one), then clean the history if needed.

2.8

Update and remove

dnf -y upgrade git
apt-get install --only-upgrade -y git
dnf -y remove git

Removing Git does not delete your repositories; they are normal folders with a .git folder inside.

Commando's in deze les

2.9

Fix common problems

ProblemCauseFix
Permission denied (publickey)The server does not know your key.Add ~/.ssh/id_ed25519.pub to your account; test with ssh -T git@github.com.
! [rejected] main -> main (fetch first)The remote has commits you do not have.git pull, fix conflicts, then git push.
Merge conflictTwo people changed the same lines.Edit the file, remove the <<<<<<< markers, git add, git commit.
Wrong name or email in the last commitSettings were missing.Fix the config, then git commit --amend --reset-author --no-edit.
You are in 'detached HEAD' stateYou checked out a commit, not a branch.git switch -c new-branch to keep work, or git switch main.
fatal: not a git repositoryYou are not in the project folder.cd into it, or git init.
Lost commits after a resetThe branch moved.git reflog, then git switch -c rescue HASH.

2.10

Next steps

1Why use the GitHub noreply email in user.email?

Every commit shows the email. The noreply address keeps your real email private.

2You pushed a password to GitHub. What do you do first?

Rotate the password (make a new one). Removing it from the history comes after.

Alle commando's in dit hoofdstuk