Search for a command to run...
Install Git 2.56 on Linux, macOS and Windows, configure your identity, SSH keys, credential helpers and commit signing, and work with branches the modern way.
Git is the distributed version control system that every DevOps workflow is built on. This guide installs the current release and configures the parts that matter day to day.
Git 2.56.0 (released September 2026) · git switch / git restore ·
Git Credential Manager for storing credentials · commit signing with an SSH or
GPG key
apt install git gives you whatever the distribution shipped — sometimes several
releases behind. That is fine for most work, but if you need the newest Git (for a
new flag or a security fix), build it from source or use a version manager.
zlib1g-dev, libssl-dev,
libcurl4-openssl-dev, libexpat1-dev, gettext, libpcre2-dev and pkg-config# Your name and email — these end up in every commit you make
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
# The default branch for new repositories
git config --global init.defaultBranch main
# The editor for commit messages
git config --global core.editor "code --wait" # or vim, nano, ...
# Check what is set
git config --global --list# Pull with rebase instead of merge commits
git config --global pull.rebase true
# Reuse conflict resolutions when rebasing
git config --global rerere.enabled true
# Show the original object when a file is renamed
git config --global diff.renames copies
# Prune deleted branches when fetching
git config --global fetch.prune true
# Use the native file system monitor on macOS and Windows
git config --global core.fsmonitor true# 1. Generate an ed25519 key
ssh-keygen -t ed25519 -C "you@example.com"
# 2. Start the agent and add the key (macOS)
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# On Linux with systemd, enable the agent once
sudo systemctl enable --now ssh-agent# 3. Copy the public key to the host
ssh-copy-id -i ~/.ssh/id_ed25519.pub you@server
# 4. Test it
ssh -T git@github.comUse a different key per service with ~/.ssh/config:
Host github.com
IdentityFile ~/.ssh/id_ed25519_github
AddKeysToAgent yes
Host gitlab.com
IdentityFile ~/.ssh/id_ed25519_gitlabDo not store passwords in plain text. Use Git Credential Manager, which stores them in the OS keychain:
# Linux, macOS and Windows with Git Credential Manager installed
git config --global credential.helper manager
# macOS only — the system keychain
git config --global credential.helper osxkeychain
# Windows only — the Windows Credential Manager
git config --global credential.helper manager# Check which helper is active
git config --global credential.helper
git credential fill # type protocol=https, host=github.com and press Ctrl-DSince Git 2.34 you can sign with an SSH key — no GPG needed:
# Use the SSH key format
git config --global gpg.format ssh
# The key to sign with
git config --global user.signingkey ~/.ssh/id_ed25519.pub
# Sign every commit automatically
git config --global commit.gpgsign true
# And every tag
git config --global tag.gpgsign true# Verify a signature
git log --show-signature -1# Start a repository and commit
git init
git add .
git commit -m "Initial commit"
# Branching — the modern commands
git switch -c feature/login # create and switch
git switch main # switch back
git switch - # switch to the previous branch
git branch -d feature/login # delete a merged branch
# Undo changes
git restore file.txt # discard unstaged changes
git restore --staged file.txt # unstage
git restore --source=HEAD file.txt # discard changes to a file
git commit --amend # fix the last commit
# Unstage
git reset HEAD file.txt
# See what changed
git status
git diff
git diff --staged
git log --oneline --graph --decorate
# Pull with rebase
git pull --rebase
# Sync a branch with the main branch
git rebase main
# or merge the other way
git merge main
# Undo a merge or rebase
git reset --hard ORIG_HEAD
# Stash work in progress
git stash push -m "wip"
git stash list
git stash pop
# Worktrees — a second checkout of the same repository
git worktree add ../myapp-feature feature/logingit config --global so every repository inherits it.git switch and git restore instead of the older git checkout — they are
explicit about what they change..gitignore from day one, and add a secret scanner to
your pre-commit hooks.pull.rebase true so a pull never creates an accidental merge commit.rerere so a resolved conflict is remembered for the next rebase.git maintenance run --auto (or git maintenance start) to keep the
repository healthy.gh and glab for pull requests, issues and pipelines — they handle the
API details and authentication for you.Set up Git and the GitHub and GitLab command line clients with authentication, branching strategies, credential helpers and the everyday commands every DevOps engineer relies on.
Install GitHub CLI 2.102 on Linux, macOS and Windows, authenticate with GitHub, and manage pull requests, issues, workflows and releases from your terminal.