Interactive Git & GH CLI Studio 1 developer view

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)

Step 1 • Install & Auth

Install & Authenticate CLI

Install GitHub CLI on Windows and log in using browser verification:

winget install --id GitHub.cli
gh auth login
Select GitHub.com → HTTPS → Web Browser → Enter Code
Step 2 • Initialize

Initialize & Stage Local Folder

Turn your project directory into a git repository with an initial commit:

git init
git add . && git commit -m "feat: implement core authentication"
Verify status with git status
Step 3 • Push Remote

Create 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 --push
Or run interactive wizard: gh repo create
config

Configure 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"
config

List All Active Git Configurations

Displays all global, system, and local repository settings along with the config file origins.

git config --list --show-origin
config

Generate 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"
config

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 login
config

Check Active GitHub CLI Authentication Status

Verifies which GitHub user account is active, OAuth token scopes, and current protocol (HTTPS/SSH).

gh auth status
workflow

Initialize 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"
workflow

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 main
workflow

1-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 --push
workflow

Add 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 -v
workflow

Fetch 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 main
branches

Create 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-v2
branches

List Local & Remote Branches

Lists all local branches as well as all tracked remote branches on origin.

git branch -a
branches

Rename Current Local Branch

Renames your currently checked out local branch to 'feature/auth-v2'.

git branch -m feature/auth-v2
branches

Merge 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"
branches

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-v2
diff-inspect

Inspect 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.js
diff-inspect

Compare Differences Between Two Branches or Commits

Compares commit differences and file modifications between main and 'feature/auth-v2'.

git diff main..feature/auth-v2
diff-inspect

Inspect 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 HEAD
diff-inspect

Show Commit Metadata & Exact Patch Diff

Shows detailed commit metadata, author information, timestamps, and line-by-line diff of the latest commit.

git show --stat HEAD
stash

Save 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"
stash

List All Saved Stashes

Displays all indexed stashes (stash@{0}, stash@{1}) with their timestamps and messages.

git stash list
stash

Apply 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 pop
stash

Create 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}
stash

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 clear
tags

Create 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"
tags

List All Tags Matching Pattern

Lists all tags with their corresponding one-line annotation descriptions.

git tag -n -l 'v*'
tags

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 --tags
tags

Delete 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.0
undo-rebase

Rebase 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 main
undo-rebase

Interactive Rebase to Squash & Reorder Commits

Opens terminal editor to squash (combine), reword, or drop the last 3 commits.

git rebase -i HEAD~3
undo-rebase

Undo Commits but Keep Changes Staged

Undoes the last 3 commit(s) while retaining all your modified code staged in index.

git reset --soft HEAD~3
undo-rebase

Hard 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-v2
undo-rebase

View 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}
undo-rebase

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 HEAD
gh-cli

Create 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" --web
gh-cli

Checkout PR by Number locally

Downloads and switches to the remote branch of PR #42 for local testing and code review.

gh pr checkout 42
gh-cli

Clone a Repository by Short Name

Clones 'my-awesome-project' from your GitHub account without typing full HTTPS/SSH URLs.

gh repo clone my-awesome-project
gh-cli

List Open Issues on Current Repository

Displays the top 10 open issues, assignees, and labels in your terminal.

gh issue list --limit 10
gh-cli

Publish 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-notes
Spotlight Hardware & Tools

Handpicked Partner Deals & Gear

Curated mechanical keyboards, 4K monitors, coding software, and developer workstation bundles with verified partner discounts.

100% Curated & Tested

Vetted by software engineers

Instant Partner Pricing

Amazon IN, US & verified stores

Refreshed Deals

Daily discounts & promo codes

Showing 0 of 0 Spotlight

Cite & Link This Resource

Backlink Magnet

Writing 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
DevDossier Ecosystem20 Platforms

Find Us Everywhere

We publish, stream, and collaborate across every major developer & design platform. Follow along wherever you feel at home.

20+ Platforms
Global Presence
Developer First
Open Ecosystem
Daily Updates
Real-time Content
100% Free
Open Resources
🎁 Partner Rewards⚡ Instant 100+ Points

Earn Microsoft Rewards with DevDossier

Redeem free Xbox Game Pass subscriptions, gift cards, developer tools, and Bing search points directly through Microsoft's official Rewards program.