My Most Used Git Commands

My Most used git command list with examples

  • git status
  • git add
  • git commit
  • git push
  • git pull
  • git checkout
  • git merge

Git Status

git status result

Git Add

vscode staged changes
git add dir/file1.js dir/file2.js

Git Commit

git commit -m 'update article with pictures'

Git Push

git push
git push -u origin <branch_name>
git push --set-upstream <remote> <branch_name>

Git Pull

git pull

Git checkout

git checkout <branch name>
git checkout

Git checkout -b

git checkout -b <branch name>

Git Merge

How to merge a feature branch into the main branch

git checkout maingit merge <branch name>
git merge main
How to merge a feature branch into the main branch

How to merge the main branch into a feature branch

git pull
git checkout <feature-branch>git merge <branch name>
git merge feature
How to merge the main branch into a feature branch

Often used Git commands List with examples

  • git log — oneline
  • git branch -d
  • git reset
  • git rebase

git log — oneline

git log --oneline

git branch -d

git branch -d

git reset head

git reset head <commit hash>

Notable mentions from Developer friends of their most used git commands

  • git rm -cached flag
  • git stash
  • git cherry pick <commit hash >
  • git rebase

git rm — cached flag

git rm <file Relative path> --cached

git stash

git stash --include-untracked or git stash -u

git cherry pick <commit hash >

git cherrypick 0c2e231

git rebase

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store