My Most Used Git Commands

Here are some of the most commonly use git commands I use. Wanted to put it in one place to reference back to whenever.

Amend an unpushed commit message

Terminal
git commit --amend

Delete a branch locally

Terminal
git branch -d localBranchName

Delete a branch remotely

Terminal
git push origin --delete remoteBranchName

Remove commit based on commit history position

Terminal
git reset --hard HEAD~1

Remove .env from GitHub

Terminal
git rm -r --cached .env
git commit -m 'untracking .env'
git push origin master

Remove node_modules

Terminal
rm -rf node_modules
Published: Jan 9, 2024
Get the latest from me on my newsletter! I'll share resources I've come across and keep you up to date on my latest projects.