Terminal GuideTerminal Guide

Git Cheatsheet

Essential Git commands organized by category. Keep this reference handy for your daily development workflow.

5 min readLast updated: 2024
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Setup

git initInitialize repo
git clone [url]Clone repo
git config --global user.nameSet name
git config --global user.emailSet email

Basic

git statusCheck status
git add [file]Stage file
git add .Stage all
git commit -m "msg"Commit changes

Branch

git branchList branches
git branch [name]Create branch
git checkout [branch]Switch branch
git checkout -b [name]Create & switch
git merge [branch]Merge branch
git branch -d [name]Delete branch

History

git logView history
git log --onelineCompact history
git diffUnstaged changes
git diff --stagedStaged changes
git show [commit]Commit details

Undo

git checkout -- [file]Discard changes
git reset [file]Unstage file
git reset --soft HEAD~1Undo commit (keep)
git reset --hard HEAD~1Undo commit (discard)
git revert [commit]Revert commit

Remote

git remote -vList remotes
git remote add [name] [url]Add remote
git pushPush to remote
git pullPull from remote
git fetchFetch changes

Downloadable Image Preview

Failed to generate preview

Setup & Config

git config --global user.name "[name]"Set your name
git config --global user.email "[email]"Set your email
git initInitialize a new repo
git clone [url]Clone a repository

Basic Commands

git statusCheck repo status
git add [file]Stage a file
git add .Stage all changes
git commit -m "[message]"Commit staged changes
git pushPush to remote
git pullPull from remote

Branching

git branchList branches
git branch [name]Create new branch
git checkout [branch]Switch to branch
git checkout -b [name]Create and switch
git merge [branch]Merge branch
git branch -d [name]Delete branch

History & Diff

git logView commit history
git log --onelineCompact history
git diffShow unstaged changes
git diff --stagedShow staged changes
git show [commit]Show commit details

Undo & Reset

git checkout -- [file]Discard file changes
git reset [file]Unstage a file
git reset --soft HEAD~1Undo last commit (keep changes)
git reset --hard HEAD~1Undo last commit (discard changes)
git revert [commit]Revert a commit

Remote

git remote -vList remotes
git remote add [name] [url]Add remote
git fetchFetch remote changes
git push -u origin [branch]Push and track branch

Related Articles