Skip to content
>_devvkit
$devvkit learn --librarie git-guide

Git Guide

[vcs][version-control][cli][collaboration]
Universal
Install
# macOS
brew install git

# Linux
sudo apt install git

# Windows
winget install Git.Git

Git is the de facto standard for version control. Every developer encounters it daily.

The mental model that unlocks Git mastery is the directed acyclic graph. Every commit is a node; branches are movable pointers; HEAD is where you stand.

Setup & Config

Configure identitySet name and email for commits.
git config --global user.name 'Your Name'
git config --global user.email 'you@example.com'
Set default branchChange default branch name.
git config --global init.defaultBranch main

Basic Workflow

Stage changesAdd files to staging.
git add file.js
git add .
CommitSave staged changes.
git commit -m 'feat: add auth'
StatusShow modified/staged/untracked files.
git status

Branching & Merging

Create branchCreate new branch.
git branch feature-x
Switch branchMove HEAD to another branch.
git checkout feature-x
Create and switchCreate and switch in one command.
git checkout -b feature-x
Merge branchIntegrate changes.
git checkout main
git merge feature-x

History & Debugging

View logShow commit history.
git log --oneline --graph -10
Blame a fileShow who modified each line.
git blame src/index.js

Undoing Changes

Unstage fileRemove from staging.
git restore --staged file.js
Discard changesRevert uncommitted changes.
git restore file.js
Amend commitChange last commit message.
git commit --amend -m "new message"

Collaboration

Push to remoteUpload commits.
git push origin main
Pull from remoteFetch and merge.
git pull origin main

Advanced

Stash changesTemporarily save uncommitted work.
git stash
git stash pop
Interactive rebaseSquash/reorder recent commits.
git rebase -i HEAD~3