🟢 Beginner Git Commands (Must Know First)
These are the commands you’ll use every day.
⚙️ Setup (one-time)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Check config:
git config --list
📁 Start a project
Create new repo:
git init
Clone existing repo:
git clone https://github.com/user/repo.git
📌 Basic workflow (core Git loop)
Check status:
git status
Add files:
git add .
Commit changes:
git commit -m "your message"
Send to GitHub:
git push
Get updates:
git pull
🟡 Intermediate Git Commands (Real Development Work)
This is where Git starts becoming powerful.
🌿 Branching (VERY important)
Create branch:
git branch feature-branch
Switch branch:
git checkout feature-branch
Create + switch at once:
git checkout -b feature-branch
List branches:
git branch
Delete branch:
git branch -d feature-branch
🔀 Merging
Switch to main:
git checkout main
Merge branch:
git merge feature-branch
🌐 Remote repositories
Add remote:
git remote add origin https://github.com/user/repo.git
Check remotes:
git remote -v
Push branch:
git push origin main
Push new branch:
git push -u origin feature-branch
🔄 Sync with remote
Fetch changes (no merge):
git fetch
Pull changes (fetch + merge):
git pull
🔵 Advanced Git Commands (Professional Level)
These are used in real teams, open source, and production systems.
⏪ Undo changes (VERY important)
Undo last commit (keep changes):
git reset --soft HEAD~1
Undo last commit (remove changes):
git reset --hard HEAD~1
Undo file changes:
git checkout -- filename
Restore file from commit:
git restore filename
🧠 Stashing (save work temporarily)
Save changes without committing:
git stash
List stashes:
git stash list
Apply stash:
git stash apply
Remove stash:
git stash drop
🔍 Inspect history
View commits:
git log
Compact log:
git log --oneline
Graph view:
git log --graph --oneline --all
See file changes:
git diff
🧩 Rewriting history (advanced)
Edit last commit message:
git commit --amend
Squash commits (interactive):
git rebase -i HEAD~3
🚨 Conflict handling
When merge conflict happens:
git status
Fix files manually → then:
git add .
git commit
🌍 Advanced remote control
Change remote URL:
git remote set-url origin NEW_URL
Remove remote:
git remote remove origin
🧪 Cherry-picking (select commits)
Apply specific commit:
git cherry-pick commit-id
🧭 Rebase (clean history)
Rebase branch:
git rebase main
Continue after conflict:
git rebase --continue
Cancel rebase:
git rebase --abort
🧠 Git mastery workflow (real-world pattern)
This is what developers actually do:
git checkout -b new-feature
# work on code
git add .
git commit -m "add feature"
git push -u origin new-feature
Then open a Pull Request on GitHub.
🚀 Beginner → Advanced roadmap
🟢 Beginner
- git init
- add / commit / push / pull
- status
🟡 Intermediate
- branches
- merge
- remote repos
- fetch
🔵 Advanced
- rebase
- stash
- cherry-pick
- reset / revert
- conflict resolution
💡 Final Advice
Don’t try to memorize everything.
Instead focus on:
branch → commit → push → pull request
Everything else builds on that.
Top comments (0)