My Most Used Git Commands

Jan 9, 202452 views1 min read

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