๐ Top Git Commands
Complete Beginner to Advanced Guide
Before jumping into commands, understand these key terms: ๐น Repository (Repo) A repository is a project folder that Git tracks. It stores all files and their version history. ๐น Working Directory This is your current project folder where you edit files. ๐น Staging Area (Index) A temporary area where changes are prepared before committing. ๐น Commit A saved snapshot of your project at a specific time. ๐น Branch A separate line of development. It allows you to work on new features without affecting the main project. ๐น Merge Combines changes from one branch into another. ๐น Remote Repository An online version of your project (like on GitHub).
๐ Git Workflow
Working Directory → Staging → Local Repo → Remote Repo
๐ฟ Branching Visual
main ─────────●────────
↘ feature ──●──●
↗ merge ─────●
⚔ Git vs GitHub
| Git | GitHub |
|---|---|
| Version Control | Hosting Platform |
| Works Offline | Cloud Based |
| Tracks Changes | Shares Projects |
๐ 1–10 Basics
1. Initialize Repo
git init2. Clone Repo
git clone <repo-url>3. Status
git status4. Add File
git add file.txt5. Add All
git add .6. Commit
git commit -m "message"7. Add & Commit
git commit -am "message"8. Log
git log9. Diff
git diff10. Diff Staged
git diff --staged๐ฟ 11–20 Branching
11. List Branches
git branch12. Create Branch
git branch new-branch13. Checkout Branch
git checkout branch14. Switch Branch
git switch branch15. Create & Switch
git switch -c new-branch16. Merge
git merge branch17. Delete Branch
git branch -d branch18. Force Delete
git branch -D branch19. Abort Merge
git merge --abort20. Stash
git stash๐ 21–30 Remote Commands
git remote -vgit remote add origin <url>git push -u origin maingit pushgit pullgit fetchgit push origin branchgit push --forcegit push origin --delete branchgit pull origin branch๐งน 31–36 Reset & Cleanup
⚠ Be careful with reset --hard and force push.
git reset filegit reset --hardgit reset --soft HEAD~1git revert commit-idgit clean -fgit clean -fd๐ท 37–42 Tags & Logs
git taggit tag v1.0git tag -a v1.0 -m "Version 1"git show taggit log --onelinegit log --graph⚙ 43–50 Advanced & Config
git config --global user.name "Name"git config --global user.email "email"git config --listgit blame filegit cherry-pick commitgit rebase branchgit refloggit archive --format=zip HEAD > project.zip⚔ Merge Conflict Example
<<<<<<< HEAD
Your Code
=======
Incoming Code
>>>>>>> branch
๐ฏ Remember
git add → git commit → git push
Comments
Post a Comment