π’ 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)