Git & GitHub

The Git and GitHub commands I am most likely to forget between projects.

Developer Tools Beginner–Intermediate

Repository Basics

Commands for creating, inspecting, and recording changes in a repository.

Commands for creating, inspecting, and recording changes in a repository.
Term / Syntax Name Description Example
git init Initialize repository Creates a new local Git repository in the current directory. git init
git status Working tree status Shows tracked, modified, staged, and untracked files. git status
git add Stage changes Adds changes to the staging area for the next commit. git add src/app.js
git commit Create commit Records the staged snapshot with a message. git commit -m "Add search filter"
git diff Inspect changes Shows unstaged differences by default. git diff
git diff --staged Inspect staged changes Shows changes currently staged for the next commit. git diff --staged

Branches

Commands for creating, switching, merging, and cleaning up branches.

Commands for creating, switching, merging, and cleaning up branches.
Term / Syntax Name Description Example
git branch List/create branches Lists local branches or creates a new branch when given a name. git branch feature/search
git switch Switch branch Changes the current branch. git switch main
git switch -c Create and switch Creates a new branch and switches to it. git switch -c feature/search
git merge Merge branch Integrates the named branch into the current branch. git merge feature/search
git branch -d Delete merged branch Deletes a local branch after Git confirms it is merged. git branch -d feature/search

Remotes & Syncing

Commands for connecting local work with remote repositories such as GitHub.

Commands for connecting local work with remote repositories such as GitHub.
Term / Syntax Name Description Example
git remote -v List remotes Shows configured remote names and URLs. git remote -v
git remote add Add remote Connects a named remote repository. git remote add origin https://github.com/user/repo.git
git fetch Fetch remote history Downloads remote commits and refs without merging them. git fetch origin
git pull Fetch + integrate Fetches from a remote branch and integrates according to configuration. git pull origin main
git push Push commits Uploads local commits to a remote branch. git push origin main
git push -u Set upstream Pushes and establishes the default upstream tracking branch. git push -u origin feature/search

History & Recovery

Commands for inspecting history and safely undoing common local changes.

Commands for inspecting history and safely undoing common local changes.
Term / Syntax Name Description Example
git log Commit history Shows commit history; options can make it more compact or graphical. git log --oneline --graph --decorate
git restore Restore working file Restores file contents from another Git state, commonly HEAD. git restore src/app.js
git restore --staged Unstage file Removes a file from the staging area without discarding working changes. git restore --staged src/app.js
git revert Reverse commit Creates a new commit that reverses a previous commit. git revert abc1234
git stash Temporarily store changes Saves uncommitted changes so the working tree can be cleaned temporarily. git stash push -m "WIP search"
git stash pop Restore stash Applies and removes the most recent stash if successful. git stash pop