Create a branch from a specific commit hash
git branch branch_name <commit-hash>Compare latest commit with previous commit
git showUndo git revert
git cherry-pick <id-of-reverted-commit>Safely roll back to a specific commit
git revert --no-commit <commit-id>..HEAD
git commit -m "..."Show all the recent commits with their changes
git log -pCompare branches
Green/red changes in 2nd branch relative to 1st branch
git diff master..devCommit current changes to separate new branch
git stash
git checkout -b new_branch
git stash pop
git add <whatever>
git commit -m "Whatever"
git push -u origin new_branchHow to restore your main branch to the remote version
e.g. when you’ve accidentally made minor unimportant commits to the local main branch, causing a merge conflict when you pull, and you want to throw away those commits
git merge --abort # if still merging
git fetch origin main
git reset --hard FETCH_HEAD
git clean -df # NB will delete filesDelete remote branch
When you have deleted the local branch with git branch -d branchname and now want to delete the remote branch too
git push origin -d branchnameCompare last commit with 3 commits before that
git diff HEAD~3