DevOpsLesson
DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER

Git Cheatsheet

Showing 45 of 45 commands

Setup & Config

Install, configure identity and initialise repositories

5 commands
git config --global user.name "<name>"beginner

Set the author name used on your commits

git config --global user.email "<email>"beginner

Set the author email used on your commits

git config --listbeginner

Show all current Git configuration values

git initbeginner

Create a new empty Git repository in the current directory

git clone <url>beginner

Copy a remote repository to your machine

Staging & Committing

Track changes, stage files and record commits

6 commands
git statusbeginner

Show the working tree status - staged, unstaged and untracked files

git add <file>beginner

Stage changes for the next commit

git commit -m "<message>"beginner

Record staged changes to the repository history

git diffbeginner

Show changes between working tree and the index

git rm <file>intermediate

Remove a file from the working tree and stage the deletion

git mv <src> <dest>beginner

Move or rename a file and stage the change

Branching

Create, switch and manage branches

5 commands
git branchbeginner

List all local branches (current marked with *)

git switch <branch>beginner

Switch to an existing branch

git switch -c <branch>beginner

Create a new branch and switch to it

git branch -d <branch>beginner

Delete a branch that has been merged

git branch -m <new-name>intermediate

Rename the current branch

Merging & Rebasing

Combine branches and rewrite history

4 commands
git merge <branch>intermediate

Merge another branch into the current branch

git rebase <branch>advanced

Reapply your commits on top of another branch for a linear history

git rebase -i HEAD~<n>advanced

Interactively rewrite the last n commits

git cherry-pick <commit>advanced

Apply a specific commit from another branch

Remotes & Syncing

Push, pull and manage remote repositories

5 commands
git remote -vbeginner

List configured remote repositories and their URLs

git remote add <name> <url>beginner

Add a new remote repository

git fetch <remote>intermediate

Download objects and refs without merging

git pullbeginner

Fetch from the remote and merge into the current branch

git pushbeginner

Upload local commits to the remote

Undoing Changes

Reset, revert and recover from mistakes

6 commands
git restore <file>beginner

Discard uncommitted changes in a file

git reset <file>beginner

Unstage a file while keeping its changes

git reset --soft HEAD~1intermediate

Undo the last commit but keep changes staged

git reset --hard <commit>advanced

Reset the branch and working tree to a commit, discarding changes

git revert <commit>intermediate

Create a new commit that undoes a previous commit

git reflogadvanced

Show a log of where HEAD has been - your safety net

Stashing

Temporarily shelve work in progress

5 commands
git stashintermediate

Save uncommitted changes and revert to a clean tree

git stash listbeginner

List all stashed change sets

git stash popintermediate

Apply the most recent stash and remove it from the list

git stash applyintermediate

Apply a stash but keep it in the stash list

git stash dropintermediate

Delete a specific stash

History & Inspection

Browse logs, blame and inspect commits

5 commands
git logbeginner

Show the commit history

git show <commit>beginner

Show the details and diff of a specific commit

git blame <file>intermediate

Show who last modified each line of a file

git diff <a>..<b>intermediate

Compare two commits or branches

git bisect startadvanced

Binary-search commit history to find a bug-introducing commit

Tags & Releases

Mark release points in history

4 commands
git tagbeginner

List all tags

git tag -a <name> -m "<msg>"intermediate

Create an annotated tag for a release

git push <remote> <tag>intermediate

Push a tag to the remote

git tag -d <name>intermediate

Delete a local tag

Git Cheatsheet

Every Git command you need - with flags, real-world examples, and pro tips. Search, filter by difficulty, and copy with one click.

devopslesson.com/tools/cheatsheets/git

45 commands9 categories

Setup & Config

5 commands
git config --global user.name "<name>"beginner

Set the author name used on your commits

git config --global user.name "Jane Doe"

💡 Use --global for all repos, or omit it to set per-repository config.

git config --global user.email "<email>"beginner

Set the author email used on your commits

git config --global user.email "jane@example.com"
git config --listbeginner

Show all current Git configuration values

git config --list --show-origin
git initbeginner

Create a new empty Git repository in the current directory

git init
git clone <url>beginner

Copy a remote repository to your machine

git clone https://github.com/user/repo.git

Staging & Committing

6 commands
git statusbeginner

Show the working tree status - staged, unstaged and untracked files

git status -s
git add <file>beginner

Stage changes for the next commit

git add .

💡 Use git add -p to review and stage hunks one at a time.

git commit -m "<message>"beginner

Record staged changes to the repository history

git commit -m "Add login endpoint"
git diffbeginner

Show changes between working tree and the index

git diff --staged
git rm <file>intermediate

Remove a file from the working tree and stage the deletion

git rm --cached secret.env
git mv <src> <dest>beginner

Move or rename a file and stage the change

git mv app.js src/app.js

Branching

5 commands
git branchbeginner

List all local branches (current marked with *)

git branch -a
git switch <branch>beginner

Switch to an existing branch

git switch feature/login

💡 git switch is the modern replacement for git checkout <branch>.

git switch -c <branch>beginner

Create a new branch and switch to it

git switch -c feature/payments
git branch -d <branch>beginner

Delete a branch that has been merged

git branch -d feature/login
git branch -m <new-name>intermediate

Rename the current branch

git branch -m main

Merging & Rebasing

4 commands
git merge <branch>intermediate

Merge another branch into the current branch

git merge feature/login
git rebase <branch>advanced

Reapply your commits on top of another branch for a linear history

git rebase main

💡 Never rebase commits that have been pushed and shared with others.

git rebase -i HEAD~<n>advanced

Interactively rewrite the last n commits

git rebase -i HEAD~3

💡 Great for squashing WIP commits before opening a pull request.

git cherry-pick <commit>advanced

Apply a specific commit from another branch

git cherry-pick a1b2c3d

Remotes & Syncing

5 commands
git remote -vbeginner

List configured remote repositories and their URLs

git remote -v
git remote add <name> <url>beginner

Add a new remote repository

git remote add origin git@github.com:user/repo.git
git fetch <remote>intermediate

Download objects and refs without merging

git fetch origin
git pullbeginner

Fetch from the remote and merge into the current branch

git pull --rebase origin main

💡 git pull --rebase keeps history linear and avoids noisy merge commits.

git pushbeginner

Upload local commits to the remote

git push -u origin main

💡 Prefer --force-with-lease over --force to avoid overwriting teammates’ commits.

Undoing Changes

6 commands
git restore <file>beginner

Discard uncommitted changes in a file

git restore src/app.js
git reset <file>beginner

Unstage a file while keeping its changes

git reset HEAD app.js
git reset --soft HEAD~1intermediate

Undo the last commit but keep changes staged

git reset --soft HEAD~1
git reset --hard <commit>advanced

Reset the branch and working tree to a commit, discarding changes

git reset --hard HEAD~1

💡 Destructive - --hard permanently discards uncommitted work.

git revert <commit>intermediate

Create a new commit that undoes a previous commit

git revert a1b2c3d

💡 Safe for shared branches - it does not rewrite history.

git reflogadvanced

Show a log of where HEAD has been - your safety net

git reflog

💡 Use reflog to recover “lost” commits after a bad reset or rebase.

Stashing

5 commands
git stashintermediate

Save uncommitted changes and revert to a clean tree

git stash push -m "wip: login form"
git stash listbeginner

List all stashed change sets

git stash list
git stash popintermediate

Apply the most recent stash and remove it from the list

git stash pop
git stash applyintermediate

Apply a stash but keep it in the stash list

git stash apply stash@{1}
git stash dropintermediate

Delete a specific stash

git stash drop stash@{0}

History & Inspection

5 commands
git logbeginner

Show the commit history

git log --oneline --graph --all
git show <commit>beginner

Show the details and diff of a specific commit

git show a1b2c3d
git blame <file>intermediate

Show who last modified each line of a file

git blame src/app.js
git diff <a>..<b>intermediate

Compare two commits or branches

git diff main..feature
git bisect startadvanced

Binary-search commit history to find a bug-introducing commit

git bisect start && git bisect bad && git bisect good v1.0

💡 A powerful way to pinpoint exactly which commit broke something.

Tags & Releases

4 commands
git tagbeginner

List all tags

git tag -l "v1.*"
git tag -a <name> -m "<msg>"intermediate

Create an annotated tag for a release

git tag -a v1.2.0 -m "Release 1.2.0"
git push <remote> <tag>intermediate

Push a tag to the remote

git push origin v1.2.0
git tag -d <name>intermediate

Delete a local tag

git tag -d v1.2.0
devopslesson.comFree DevOps Cheatsheets · Tutorials · Roadmaps