Skip to main content

Git & GitHub CLI Cheatsheet

A short, practical list of common Git commands for daily work. Focuses on staging, branching, reviewing, fixing mistakes, and team workflow.


Basic Commands​

Check repo status​

git status

View changes (unstaged / staged)​

git diff
git diff --staged

Stage files​

git add <file>
git add .

Commit changes​

git commit -m "message"

Branching​

List branches​

git branch

Create a new branch​

git checkout -b feature/new-topic

Switch branch​

git checkout main

Working with Remote​

Pull latest changes​

git pull

Push current branch​

git push

Set upstream branch (first push)​

git push -u origin <branch>

Fixing Mistakes​

Undo last commit (keep changes)​

git reset --soft HEAD~1

Undo last commit (discard changes)​

git reset --hard HEAD~1

Restore a modified file​

git restore <file>

Unstage a file​

git restore --staged <file>

Reviewing Code​

Show commit history​

git log --oneline --graph --decorate

Show commit details​

git show <commit>

Stash​

Save changes temporarily​

git stash

List stashes​

git stash list

Apply last stash​

git stash apply

Merging and Rebasing​

Merge a branch into current​

git merge <branch>

Rebase onto another branch​

git rebase main

Clean Up​

Delete local branch​

git branch -d <branch>

Delete remote branch​

git push origin --delete <branch>

GitHub CLI (gh) & PR Workflow​

gh auth status # Check active GitHub login
gh pr create --fill # Create a PR from the current branch
gh pr list # List open pull requests
gh pr checks # Check CI status for the current PR
gh pr view --web # Open the PR in your browser
gh pr merge --squash --delete-branch # Merge PR and delete the branch
gh run list -L 5 # List the 5 most recent GitHub Actions runs
gh release list # List releases

Notes​

  • Use git restore instead of git checkout <file> (modern Git).
  • Use git switch when switching branches.
  • Keep commit messages short, consistent, and clear.

References​