20+ Most Used Git & GitHub Commands Every Developer Should Know (With Detailed Examples)


Initializing & Setting Up Repositories
1. git init
Initialize a new Git repository in your current directory.
git init
Creates a .git
folder to track your project.
2. git clone
Clone a remote repository to your local machine.
git clone https://github.com/username/repo.git
Checking Status & Changes
3. git status
Displays the status of staged, unstaged, and untracked files.
git status
4. git diff
Shows differences between working directory and the index (or last commit).
git diff
Adding & Committing Changes
5. git add
Stages changes to be committed.
git add . # add all files
git add file1.js file2.css # add specific files
6. git commit -m "message"
Saves staged changes with a message.
git commit -m "Fixed login bug"
7. git commit -am "message"
Adds and commits tracked files in one step.
git commit -am "Quick fix"
Remote Repositories
8. git remote add origin
Link local repo to a remote GitHub repo.
git remote add origin https://github.com/username/repo.git
9. git push
Push commits to remote repository.
git push origin main
10. git pull
Fetch and merge changes from the remote repo.
git pull origin main
11. git fetch
Fetches updates from the remote without merging.
git fetch origin
Branching & Merging
12. git branch
Create or list branches.
git branch # list branches
git branch feature # create new branch
13. git checkout
Switch to a branch.
git checkout feature
14. git merge
Merge one branch into another.
git checkout main
git merge feature
Stashing Changes
15. git stash
Temporarily save uncommitted changes.
git stash
16. git stash pop
Reapply stashed changes.
git stash pop
Undoing Mistakes
17. git reset
Unstage a file or revert commits.
git reset file.js # unstage file
git reset --hard HEAD~1 # delete last commit
18. git revert
Undo a specific commit by creating a new one.
git revert <commit-hash>
19. git checkout -- filename
Discard changes to a file.
git checkout -- index.html
Configuration & Logs
20. git config
Configure Git settings.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
21. git log
View commit history.
git log
Use git log --oneline
for a compact view.
Bonus Tips
Create Aliases
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
π¬ Have questions or got stuck while following this guide?
Drop your doubts in the comments β Iβd love to help you out!
β βοΈ Written by Rohit @ TechWithRohit
Subscribe to my newsletter
Read articles from Rohit Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Rohit Kumar
Rohit Kumar
π¨βπ» Working IT professional | βοΈ Beginner-friendly tech writer I simplify tools like Git, SQL, and developer workflows so that even total beginners can get started with confidence. π On a mission to break down complex tech into easy steps β one blog at a time. π Topics I write about: Git, GitHub, SQL, Dev tools, Productivity for new developers π‘ Letβs grow together β follow for simple, clear, no-fluff tutorials.