We use cookies to understand how the site is used and to display ads. Analytics and advertising only run after you accept. You can change your choice anytime. Privacy policy

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 identity· Set name and email for commits.
git config --global user.name 'Your Name'
git config --global user.email 'you@example.com'
Set default branch· Change default branch name.
git config --global init.defaultBranch main

Basic Workflow

Stage changes· Add files to staging.
git add file.js
git add .
Commit· Save staged changes.
git commit -m 'feat: add auth'
Status· Show modified/staged/untracked files.
git status

Branching & Merging

Create branch· Create new branch.
git branch feature-x
Switch branch· Move HEAD to another branch.
git checkout feature-x
Create and switch· Create and switch in one command.
git checkout -b feature-x
Merge branch· Integrate changes.
git checkout main
git merge feature-x

History & Debugging

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

Undoing Changes

Unstage file· Remove from staging.
git restore --staged file.js
Discard changes· Revert uncommitted changes.
git restore file.js
Amend commit· Change last commit message.
git commit --amend -m "new message"

Collaboration

Push to remote· Upload commits.
git push origin main
Pull from remote· Fetch and merge.
git pull origin main

Advanced

Stash changes· Temporarily save uncommitted work.
git stash
git stash pop
Interactive rebase· Squash/reorder recent commits.
git rebase -i HEAD~3