I use the git cli every single day for my source code management needs. Sometimes I forget how to do certain things with git or I just haven’t automated it yet, so I’m writing it all down so that I have something to easily refer to:

Squash all commits on a branch

git reset $(git merge-base master $(git rev-parse --abbrev-ref HEAD))


Get the number of commits added to your branch

git rev-list --count master..


Squash and merge your X latest commits

git reset --soft HEAD~3 && 
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"


Create a repo on GitHub

hub create [NAME] [-p] [-d DESCRIPTION] [-h HOMEPAGE]

Merging in a branch with lots of commits without a merge commit

git merge --squash v1.0
git commit

Delete a remote branch

git push origin --delete branch-name

Delete local branch

git branch -D branch-name

Show diff of last commit

git show

Undo a git add

git reset <file>