⚡ Introducing Ubify Nexus: The all-in-one Operating System for YouTube Learners & Researchers.Claim 3 Months Free Pro →
Back to Reference Guides
Developer ReferenceGit 2.40+ Compatible

Git & GitHub CLI Commands Cheat Sheet

Everyday Git commands for repository setup, staging, branching, rebasing, stashing, and conflict resolution.

Repository Setup & Initialization

git initInitialize an existing directory as a new Git repository
git clone <repo-url>Clone an existing remote repository onto your local machine
git statusCheck modified, staged, and untracked files in the working directory
git log --oneline --graph --decorateView commit history as a clean, single-line visual branch tree

Staging & Committing Changes

git add <file>Stage a single file for the next commit
git add .Stage all modified and new files in the current working directory
git commit -m "feat: descriptive message"Commit staged snapshot with an atomic message
git commit --amend --no-editAdd staged changes to the most recent commit without editing message
git diffShow unstaged changes between working directory and the staging area
git diff --stagedShow changes between staged files and the last commit

Branching & Switching Contexts

git branchList all local branches (* marks the active branch)
git branch -aList both local and remote-tracking branches
git switch -c <branch-name>Create a new branch and switch to it immediately
git switch <branch-name>Switch to an existing local branch
git branch -d <branch-name>Safely delete a merged local branch
git branch -D <branch-name>Force delete a branch regardless of merge status

Merging, Rebasing & Remote Sync

git pull origin <branch>Fetch from remote repository and merge into current active branch
git push origin <branch>Push local branch commits to the remote tracking repository
git merge <branch>Merge specified branch into current active branch
git rebase <base-branch>Re-apply current branch commits on top of another branch tip
git remote -vDisplay all configured remote repository names and URLs

Stashing, Undoing & Resetting

git stashTemporarily shelve uncommitted working directory changes
git stash popRe-apply the most recently shelved changes and remove from stash list
git stash listInspect all shelved stashes
git restore <file>Discard uncommitted changes in working directory to match HEAD
git restore --staged <file>Unstage a file while preserving its working directory modifications
git revert <commit-hash>Create a new commit that safely inverts changes of a previous commit
git reset --soft HEAD~1Undo last commit but keep changes staged in index
git reset --hard HEAD~1⚠️ Dangerously destroy last commit and discard all uncommitted changes