Here's a handy part 2 to Annie Casey's Git Command Cheat Sheet.

Disclaimer: These are the commands we learned about in our "Gitting Gud at Git Hub" session with Alex Antonison. There are a lot more commands, but these have been my favorite!


git add -A

  • Stage all changes- new, modified, and deleted files.
  • Difference from git add .: this also stages deletions, which . doesn’t always catch.

Ex. You renamed a few Python scripts, deleted unused folders, and updated your README.md. Running git add -A grabs everything so you don’t miss a file before committing.

git commit -am "message"

  • Shortcut to stage and commit all modified files in one go.
  • New files won’t be included- you’ll still need to git add them manually first.

Ex. You tweaked your ETL script and updated a config file- just run this instead of git add + git commit.

git log

  • View the history of commits in your branch.
  • Use git log --oneline for a cleaner, condensed view.

Ex. You're trying to figure out when you added a new S3 path config, or want to grab a specific commit ID to roll back to.

git reset HEAD~1

  • Undo your last commit, but keep all changes in your working directory.
  • Use with caution when working on shared branches.

Ex. You realize your commit message was vague or you forgot to include a file- run this, and it’s like you never committed in the first place, but your changes are still there.

git checkout origin/main <file_name>

  • Restore a single file from the main branch to your current branch.
  • You must specify the exact file path.

Ex. You accidentally deleted your .env.example or messed up a SQL model- use this to bring just that one file back, no merge required.

git switch <branch_name>

  • Switch to another branch
  • This is a newer, more user-friendly alternative to git checkout <branch_name> (which still works, but switch is clearer and harder to misuse)

Ex: You’re on main but want to start working on the feature-cleanup-logs branch

git switch -c <new_branch_name>

  • Create and switch to a new branch in one step.
  • Same thing as git checkout -b, but newer and easier to read.

git rm <file_name>

  • Delete a file from disk and stop tracking it in Git.
  • This both deletes the file locally and removes it from Git.

Ex. You’re cleaning up old .ipynb or .log files that shouldn’t be in the repo.

git rm --cached <file_name>

  • Stop tracking a file, but keep it on disk.
  • Best used alongside .gitignore to prevent it from being tracked again.

Ex. You accidentally committed your .env file- this removes it from version control but leaves it safely on your machine.

git rm -r <folder_name>

  • Recursively delete a folder and remove it from tracking.
  • Be sure before running this- you’re wiping out everything inside that folder.

Ex. You had an old /notebooks/ directory with outdated prototypes- this removes it fully from Git.

git branch -D <branch_name>

  • Force delete a local branch, even if it hasn’t been merged.
  • Use with caution; you won’t be warned if work is lost.

Ex. You created a test-logging branch but ended up not using it- run this to clean up locally.

git merge <branch_name>

  • Merge another branch into your current one.
  • This preserves all commit history and creates a merge commit.

Ex. You finished work in your feature-email-tracking branch and want to bring it into main. First checkout main, then run git merge feature-email-tracking.

git revert <commit_id>

  • Undo a specific commit by creating a new commit that reverses it.
  • Safer than reset for shared branches since it maintains history.

Ex. You pushed a broken change to main- use git log to find the commit, then git revert <commit> to safely undo it.

git commit --amend

  • Edit the last commit.
  • If you’ve already pushed, be cautious- this rewrites history.

Ex. You forgot to include a file or want to clean up a lazy message like “fix stuff”- this lets you fix it without creating a new commit.

git rebase <branch_name>

  • Reapply your current branch commits on top of another branch.
  • More advanced- great for cleaning commit history, but be careful on shared branches.

Ex. You’re working on feature-clean-schema, but main has had updates. Rebase keeps your history linear by placing your work on top of the latest main.