Git CheatsheetThu Feb 15 2024

If I need to look up multiple times, I should just record it in my own cheatsheet.


$ git commit --amend includes current staged commit with last commit

$ git clean -f removes untracked files

To squash commits $ git rebase -i HEAD~10 (or however many commits are specific to the branch). Change pick to squash or s. Merge Commits will update the SHA so avoid rebasing over more commits than necessary.

$ git branch -m new-name renames the current branch

$ git commit --amend renames the last commit

$ git for-each-ref --sort=-committerdate refs/heads/ sort branches by date

$ git branch | grep -v "dev" | xargs git branch -D delete all local branches except dev

$ git branch -D [branchName] delete branch

$ git checkout [branchName] return to latest commit on branch

$ git blame --ignore-rev commit commit without updating blame. This is useful for formatting commits

$ git push origin localBranch:remoteBranch push a local branch to a remote branch. Often times need to add --force


How to write a good commit message by Matej Jellus

Fix Yarn Incorrect integrity when fetching from the cache