Command Palette

Search for a command to run...

GitHubGitHub

Git Installation Guide

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.

System Requirements

  • A 64-bit operating system: Linux, macOS or Windows
  • For building from source: GCC 4.9+ or Clang, Make, zlib1g-dev, libssl-dev, libcurl4-openssl-dev, libexpat1-dev, gettext, libpcre2-dev and pkg-config
  • About 200 MB of disk space for a full build

Installation Instructions

Linux

# Debian / Ubuntu
sudo apt update
sudo apt install -y git
 
# RHEL / CentOS / Rocky / Alma
sudo dnf install -y git
 
# Fedora
sudo dnf install -y git
 
# Arch Linux
sudo pacman -S git
 
# Alpine Linux
sudo apk add --no-cache git
 
# SUSE / openSUSE
sudo zypper install -y git

Post-Installation Configuration

Identity

# 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

A Sensible Default Setup

# 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

SSH Keys

# 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.com

Use 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_gitlab

Credential Storage

Do 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-D

Signing Your Commits

Since 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

Everyday Commands

# 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/login

Troubleshooting

Best Practices

  1. Set your identity once and use git config --global so every repository inherits it.
  2. Use git switch and git restore instead of the older git checkout — they are explicit about what they change.
  3. Never commit secrets. Use .gitignore from day one, and add a secret scanner to your pre-commit hooks.
  4. Sign your commits — with an SSH key it costs nothing and proves the commit is yours.
  5. Use a credential helper, never a password in the remote URL.
  6. Rebase your branch before opening a pull request so the history stays linear.
  7. Set pull.rebase true so a pull never creates an accidental merge commit.
  8. Enable rerere so a resolved conflict is remembered for the next rebase.
  9. Use git maintenance run --auto (or git maintenance start) to keep the repository healthy.
  10. Prefer gh and glab for pull requests, issues and pipelines — they handle the API details and authentication for you.

Next Steps