Git guide
What Git does in production
Git stores project history as a graph of commits — snapshots with metadata (author, message, parent commits). Teams work on branches, merge via pull requests or direct merges, and sync through remotes (GitHub, GitLab, Bitbucket, or internal servers). Deploy pipelines pull tagged releases; configuration and infrastructure repos are versioned the same way as application code.
Core concepts
- Repository — project folder plus
.gitmetadata - Working tree — files you edit on disk
- Staging area (index) — what the next commit will include
- Commit — immutable snapshot referenced by a SHA
- Branch — movable pointer to a commit (e.g.
main) - Remote — named URL for fetch/push (usually
origin)
Typical workflow
- Clone —
git clone urlcopies repo and setsorigin - Branch —
git checkout -b feature/xfor isolated work - Stage —
git addselects changes for the next commit - Commit —
git commitrecords a snapshot locally - Pull —
git pullfetches and merges remote changes - Push —
git pushuploads commits to the remote
The .git directory
All history lives under .git/ — objects (commits, trees, blobs), refs
(branches, tags), config, and hooks. Deleting or corrupting this directory loses
local history unless you can re-clone. Server-side backups and protected branches
on the remote are your safety net.
Remotes and authentication
HTTPS remotes use username + token or password. SSH remotes use keys — see the
SSH lab for key generation, ssh-agent, and
known_hosts. Deploy keys and machine users are common on CI runners;
never commit private keys into the repo.
Merge vs rebase
Merge combines branches with a merge commit — preserves exact history. Rebase replays commits on top of another branch — linear history but rewrites SHAs. Do not rebase commits already pushed to a shared branch unless the team agrees.
Tags and releases
Lightweight or annotated tags mark release points
(v1.2.0). Pipelines trigger on tag push; production deploys often
checkout a tag SHA, not a floating branch tip.
Global and local config
~/.gitconfig— user.name, user.email, aliases.git/config— remotes, branch tracking, repo-specific settingsgit config --list --show-origin— see where each value comes from
Learning resources
- Pro Git book — git-scm.com/book
- Git reference — git-scm.com/docs
- Learn Git Branching — learngitbranching.js.org (interactive visual tutorial)
- Atlassian Git tutorial — atlassian.com/git/tutorials
Practice scenarios
Hands-on Git scenarios on live Linux VMs: git