Git & GitHub CLI Power Cheat Sheet
The complete developer handbook for modern version control. Customize variables live and copy ready-to-run Git & GitHub CLI (gh) commands for first-time project publishing, SSH keys, rebasing, stashing, and reflog recovery.
Git Architecture & Core Terminologies
Essential fundamentals: Version control lifecycle & architecture
Customize Command Variables Live
Fastest Way to Push an Existing Folder to GitHub
Complete step-by-step workflow using Windows & GitHub CLI (gh)
Install & Authenticate CLI
Install GitHub CLI on Windows and log in using browser verification:
winget install --id GitHub.cligh auth loginInitialize & Stage Local Folder
Turn your project directory into a git repository with an initial commit:
git initgit add . && git commit -m "feat: implement core authentication"git statusCreate Remote & Push in 1 Command
Publish your code straight to GitHub without opening a browser:
gh repo create my-awesome-project --public --source=. --remote=origin --pushgh repo createConfigure Global Git Username & Email
Sets the author name and email address that will be attached to every commit you make on your system.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"List All Active Git Configurations
Displays all global, system, and local repository settings along with the config file origins.
git config --list --show-originGenerate Secure Ed25519 SSH Key for GitHub
Generates a high-security SSH key pair. Copy `~/.ssh/id_ed25519.pub` and add it under GitHub Settings → SSH and GPG Keys for passwordless authentication.
ssh-keygen -t ed25519 -C "your.email@example.com"Authenticate GitHub CLI via Interactive Web Browser
Launches the official GitHub CLI authentication wizard. Select: GitHub.com → HTTPS → Yes (Git credentials) → Login with a web browser → Copy verification code → Authorize.
gh auth loginCheck Active GitHub CLI Authentication Status
Verifies which GitHub user account is active, OAuth token scopes, and current protocol (HTTPS/SSH).
gh auth statusInitialize Local Project & Make First Commit
Initializes a new Git repository in the current folder, stages all files, and creates the baseline commit.
git init
git add .
git commit -m "feat: implement core authentication"Connect Local Repo to Remote Origin
Adds 'origin' remote URL, renames active branch to 'main', and sets up upstream tracking on push.
git remote add origin https://github.com/username/my-awesome-project.git
git branch -M main
git push -u origin main1-Command Remote Creation & Push via GitHub CLI
Creates a public GitHub repository named 'my-awesome-project', sets the origin remote, and pushes all local commits in a single command. Use --private for private repos.
gh repo create my-awesome-project --public --source=. --remote=origin --pushAdd Upstream Remote (Fork Syncing)
Configures an upstream remote pointing to the original repository to fetch updates into your fork.
git remote add upstream https://github.com/username/my-awesome-project.git
git remote -vFetch vs. Pull Remote Changes
`git fetch` downloads commits and branches from remote without altering your local files. `git pull` fetches and immediately merges them into your active branch.
git fetch origin
git pull origin mainCreate and Switch to New Branch
Creates a new feature branch and immediately switches your working directory to it.
git switch -c feature/auth-v2
# Or traditional: git checkout -b feature/auth-v2List Local & Remote Branches
Lists all local branches as well as all tracked remote branches on origin.
git branch -aRename Current Local Branch
Renames your currently checked out local branch to 'feature/auth-v2'.
git branch -m feature/auth-v2Merge Feature Branch into Main with Merge Commit
Merges the specified branch into main, preserving the explicit branch merge history graph.
git checkout main
git merge --no-ff feature/auth-v2 -m "merge: integrate feature/auth-v2"Safely Delete Local & Remote Branch
Deletes the local branch if merged (-d for safe, -D for force), and removes the branch on remote GitHub.
git branch -d feature/auth-v2
git push origin --delete feature/auth-v2Inspect Unstaged vs. Staged Modifications
`git diff` shows unstaged working tree changes. `git diff --staged` shows what will be included in the next commit.
git diff
git diff --staged
git diff components/Navbar.jsCompare Differences Between Two Branches or Commits
Compares commit differences and file modifications between main and 'feature/auth-v2'.
git diff main..feature/auth-v2Inspect Git Internals (Blobs, Trees & Objects)
Inspects Git's internal object database directly. `-p` pretty-prints the raw commit, tree structure, or blob data.
git cat-file -p HEAD
git ls-tree HEADShow Commit Metadata & Exact Patch Diff
Shows detailed commit metadata, author information, timestamps, and line-by-line diff of the latest commit.
git show --stat HEADSave Stash with Descriptive Name
Temporarily shelves all modified tracked files in a named stash so you can switch branches without committing unfinished work.
git stash push -m "WIP: work on components/Navbar.js"List All Saved Stashes
Displays all indexed stashes (stash@{0}, stash@{1}) with their timestamps and messages.
git stash listApply vs. Pop Stashed Changes
`apply` re-applies stash changes while preserving the stash in your list. `pop` applies changes and immediately drops it from the stash stack.
git stash apply stash@{0}
# Or apply and remove from list:
git stash popCreate New Branch from a Stash
Checks out a new branch named 'feature/auth-v2' and applies stash@{0}, preventing merge conflicts on your current branch.
git stash branch feature/auth-v2 stash@{0}Drop a Single Stash or Clear All
Permanently deletes a specific stash index or wipes the entire stash history.
git stash drop stash@{0}
# Delete all stashes:
git stash clearCreate Annotated Semantic Release Tag
Creates a signed, annotated tag named 'v1.0.0' containing author metadata, date, and release notes.
git tag -a v1.0.0 -m "Release v1.0.0: production ready"List All Tags Matching Pattern
Lists all tags with their corresponding one-line annotation descriptions.
git tag -n -l 'v*'Push Specific Tag or All Tags to Remote
Pushes tags to GitHub, creating corresponding Releases in your repository.
git push origin v1.0.0
# Push all local tags:
git push origin --tagsDelete Local & Remote Tag
Deletes 'v1.0.0' locally and removes the tag from remote GitHub.
git tag -d v1.0.0
git push origin --delete v1.0.0Rebase Feature Branch on Top of Main
Replays your branch commits on top of the latest main commit for a clean, linear commit history.
git checkout feature/auth-v2
git rebase mainInteractive Rebase to Squash & Reorder Commits
Opens terminal editor to squash (combine), reword, or drop the last 3 commits.
git rebase -i HEAD~3Undo Commits but Keep Changes Staged
Undoes the last 3 commit(s) while retaining all your modified code staged in index.
git reset --soft HEAD~3Hard Reset Local Branch to Remote Origin
Discards all local uncommitted changes and resets your branch state exactly to origin/feature/auth-v2.
git reset --hard origin/feature/auth-v2View Reflog Safety Log to Recover Deleted Commits
Shows a chronological log of all HEAD movements (commits, checkouts, rebases). Allows recovery of discarded commits.
git reflog
# To restore lost state:
git reset --hard HEAD@{1}Safely Revert a Pushed Commit
Creates a new inverse commit that cancels out changes from the previous commit, safe for shared remote branches.
git revert HEADCreate Pull Request via CLI
Creates a new pull request directly from terminal and opens the browser PR review page.
gh pr create --title "feat: implement core authentication" --body "Automated PR from feature/auth-v2" --webCheckout PR by Number locally
Downloads and switches to the remote branch of PR #42 for local testing and code review.
gh pr checkout 42Clone a Repository by Short Name
Clones 'my-awesome-project' from your GitHub account without typing full HTTPS/SSH URLs.
gh repo clone my-awesome-projectList Open Issues on Current Repository
Displays the top 10 open issues, assignees, and labels in your terminal.
gh issue list --limit 10Publish GitHub Release with Tag & Notes
Creates a GitHub release for tag 'v1.0.0' and automatically generates changelog notes from merged PRs.
gh release create v1.0.0 --title "Release v1.0.0" --generate-notesHandpicked Partner Deals & Gear
Curated mechanical keyboards, 4K monitors, coding software, and developer workstation bundles with verified partner discounts.
Cite & Link This Resource
Backlink MagnetWriting a blog post, GitHub README, or docs? Embed a backlink snippet or badge to cite this cheat sheet.
[Git & GitHub CLI Power Cheat Sheet](https://devdossier.com/resources/git-power-cheat-sheet) - Interactive Reference & Cheat Sheet via DevDossier