Version control
Git
DevOpsTool
A distributed version-control system that records changes, supports branching, and lets teams collaborate safely on source code.
Problem it solves
Why it exists.
It solves the need to understand, review, reproduce, and undo changes without passing files around manually.
Optimized for
Where it shines.
Source code with parallel contributors, code review, release branches, and an auditable change history.
Use with care
Where not to use it.
Do not use it as a deployment system, issue tracker, or a substitute for backups and artifact storage.
Components
What it is made of.
- Repository
- Commits
- Branches and tags
- Remotes
- Merge and rebase workflows
Process
How it works.
- A change is made in the working tree
- The change is staged and committed
- Branches are reviewed and integrated
- The commit is pushed to a shared remote
Command reference
Git commands.
| Command | Purpose | Example |
|---|---|---|
git init | Create a repository in the current directory. | git init |
git clone | Download a repository and its history. | git clone https://github.com/example/project.git |
git status | Inspect the current branch and changed files. | git status --short |
git diff | Review changes before staging; use --staged for staged changes. | git diff
git diff --staged |
git add | Stage specific files for the next commit. | git add src/app/page.tsx |
git commit | Save staged changes as a commit. | git commit -m "Add command reference" |
git log | Browse commit history and branch relationships. | git log --oneline --graph --all |
git switch | Switch branches or create a new branch with -c. | git switch -c feature/git-reference |
git branch | List local branches and their tracking information. | git branch -vv |
git remote | Inspect configured remote repositories. | git remote -v |
git fetch | Download remote updates without changing your working branch. | git fetch origin |
git pull | Fetch and integrate remote changes; --ff-only refuses divergent history. | git pull --ff-only |
git push | Publish commits and set the branch upstream on its first push. | git push -u origin feature/git-reference |
git merge | Integrate another branch into the current branch. | git merge feature/git-reference |
git rebase | Replay current branch commits on a new base. Use on unpublished commits; it rewrites history. | git rebase origin/main |
git stash | Temporarily save tracked changes; -u also includes untracked files. Apply keeps the saved entry. | git stash push -u -m "Work in progress"
git stash apply |
git restore --staged | Unstage a file while keeping its working changes. | git restore --staged src/app/page.tsx |
git revert | Undo a commit by recording a new inverse commit. | git revert <commit-sha> |
git cherry-pick | Apply a specific commit to the current branch. | git cherry-pick <commit-sha> |
git tag | Create an annotated release tag; push it explicitly to share it. | git tag -a v1.0.0 -m "Release 1.0.0"
git push origin v1.0.0 |