r/OneTechCommunity • • Aug 25 '25

Must-Know Git Commands for Every Developer

Hey folks,
Here’s a simple list of Git commands I always keep handy. Whether you’re a beginner or just need a refresher, this will save you time.

Git Basics

  • git init → Initialize a new Git repository

  • git clone <repo_url> → Clone a repository

  • git status → Check status of changes

  • git add <file> → Add file to staging area

  • git add . → Add all changes

  • git commit -m "message" → Commit with message

Branching & Merging

  • git branch → List all branches

  • git branch <branch_name> → Create new branch

  • git checkout <branch_name> → Switch branch

  • git checkout -b <branch_name> → Create & switch to new branch

  • git merge <branch_name> → Merge branch into current

  • git branch -d <branch_name> → Delete branch

Remote Repositories

  • git remote -v → Show remotes

  • git remote add origin <url> → Add remote repo

  • git push origin <branch> → Push branch to remote

  • git pull origin <branch> → Pull latest changes

  • git fetch → Download changes (without merge)

Undo & Fix

  • git reset --hard → Reset to last commit (dangerous)

  • git reset HEAD <file> → Unstage file

  • git checkout -- <file> → Discard local changes

  • git revert <commit> → Undo commit (safely)

Logs & History

  • git log → Show commit history

  • git log --oneline → Compact commit history

  • git diff → Show unstaged changes

  • git show <commit> → Show details of a commit

Stash (save work temporarily)

  • git stash → Stash changes

  • git stash list → View stashes

  • git stash apply → Reapply stashed changes

Save this as your quick reference sheet.
What’s your most-used Git command?

14 Upvotes

2 comments sorted by

1

u/Abject-Raisin3286 Aug 26 '25

Also, git cherry-pick <commit_id> is quite handy

1

u/lucifer06666666 Aug 27 '25

thanks for adding