Before your first commit, Git needs to know who you are, and a few settings make daily work much smoother. This lesson covers installing Git on each platform, the three configuration levels, the settings every engineer should set, and how to connect to GitLab or GitHub securely with SSH keys.
In simple words
- git config: the command that sets your name, email and preferences. Git puts your name and email on every commit.
- Configuration levels: settings for the whole machine (system), for you (global) or for one repo (local). The most specific wins.
- SSH key: a key pair that lets you push to GitLab or GitHub safely without typing a password.
Installing Git
| Platform | Command |
|---|---|
| Ubuntu / Debian | sudo apt update && sudo apt install -y git |
| RHEL / Fedora / Amazon Linux | sudo dnf install -y git |
| macOS | xcode-select --install or brew install git |
| Windows | Git for Windows from git-scm.com (includes Git Bash) |
| Containers | apk add git (Alpine), or use an image that includes it |
Check the version. Anything from 2.40 onward has the modern commands used in this course (git switch, git restore):
git --versiongit version 2.47.1Your identity
Every commit records an author name and email. Set them once for your user:
git config --global user.name "Leela Kumar"git config --global user.email "leela@acme.dev"git config user.nameLeela KumarUse the same email as your GitLab or GitHub account, so commits are linked to your profile.
The three configuration levels
| Level | Flag | File | Applies to |
|---|---|---|---|
| System | --system | /etc/gitconfig | every user on the machine |
| Global | --global | ~/.gitconfig | you, in every repository |
| Local | --local (default) | .git/config | one repository |
More specific levels win. A common pattern is a personal email globally and a work email in work repositories:
cd ~/work/paymentsgit config user.email "leela@company.com" # local: only this repositoryMany people use conditional includes so this happens automatically for every repository under a folder:
# ~/.gitconfig[includeIf "gitdir:~/work/"] path = ~/.gitconfig-workSee all effective settings, and where each one comes from, with:
git config --listSettings worth setting today
git config --global init.defaultBranch maingit config --global pull.rebase truegit config --global core.editor "nano"git config --global alias.st "status -s"git config --global alias.lg "log --oneline --graph --all"git config --listinit.defaultBranch main: new repositories start onmain, matching GitLab and GitHub.pull.rebase true:git pullrebases your local commits on top of the remote instead of creating noisy merge commits (explained in the rebase lesson).core.editor: the editor Git opens for commit messages. Usenano,vimorcode --waitfor VS Code.- Aliases shorten frequent commands:
git st,git lg.
Other useful ones: core.autocrlf input on macOS/Linux (or true on Windows) to avoid line-ending problems, fetch.prune true to remove deleted remote branches automatically, and rerere.enabled true to remember how you resolved conflicts.
Connecting to GitLab or GitHub with SSH
You can clone over HTTPS with a personal access token, but most engineers use SSH keys: no passwords to type and nothing to leak in shell history.
# 1. Create a key pair (ed25519 is modern and short)ssh-keygen -t ed25519 -C "leela@acme.dev"# press Enter to accept ~/.ssh/id_ed25519, and set a passphrase # 2. Load it into the agent so you type the passphrase once per sessioneval "$(ssh-agent -s)"ssh-add ~/.ssh/id_ed25519 # 3. Copy the PUBLIC key and paste it in GitLab: Preferences → SSH Keyscat ~/.ssh/id_ed25519.pub # 4. Testssh -T git@gitlab.comWelcome to GitLab, @leela!Never share or commit the private key (id_ed25519 without .pub). For HTTPS, use a credential helper (git config --global credential.helper store stores tokens in plain text; prefer libsecret on Linux, osxkeychain on macOS or Git Credential Manager on Windows).
Getting help
Every command has a manual page and a short help:
git help commit # full manualgit commit -h # short summary of optionsReal-world scenario: the anonymous commits
A new CI runner image did not have user.name and user.email set, so commits made by the release job were authored by root <root@runner-7f9c.local>. Audits could not tell automated commits from human ones, and GitLab could not link them to the bot account. The fix was two lines in the job:
git config user.name "release-bot"git config user.email "release-bot@acme.dev"Setting identity explicitly in automation is a habit worth having.
Common mistakes
- Not setting
user.email, or using a different one from your Git hosting account, so commits do not show your avatar. - Using
--globalon shared machines like bastion hosts, so everyone's commits get your name. Use local config there. - Pasting the private key into GitLab instead of the
.pubfile. - Line-ending chaos between Windows and Linux; agree on
core.autocrlfor a.gitattributeswith* text=auto.
Practice
- Set your name and email globally and read them back with
git config user.nameandgit config user.email. - Set
init.defaultBranchtomain. - Create an alias
git lgforlog --oneline --graph --all. - Run
git config --listand find each value you set. - On your own machine, create an SSH key and add it to your GitLab or GitHub account.
Cheat sheet
git --versiongit config --global user.name "Name"git config --global user.email "you@example.com"git config --global init.defaultBranch maingit config --global pull.rebase truegit config --global core.editor nanogit config --global alias.lg "log --oneline --graph --all"git config --list [--show-origin]git config user.email work@company.com (this repo only)ssh-keygen -t ed25519 -C "you@example.com"ssh -T git@gitlab.comKey takeaways
- Install Git 2.40+; check with
git --version. - Set
user.nameanduser.emailbefore your first commit; they are stored in every commit. - Configuration has system, global and local levels; the most specific wins.
- A few defaults (
init.defaultBranch,pull.rebase, aliases) make daily work smoother. - Use SSH keys or a credential manager to authenticate with GitLab and GitHub.