Git's Distributed Model
Every developer has the FULL repository. Many operations are local.
๐๏ธ Centralized (SVN, CVS, Perforce)
- ุณูุฑูุฑ ูุงุญุฏ ู ุฑูุฒู ุจูุฎุฒู ูู ุงููุณุฎ.
- ุงูู Clients ุจูุงุฎุฏูุง ูุณุฎุฉ ูุดุชุบููุง ุนูููุง (check out).
- ูุงุฒู ูุช (Network) ุนุดุงู ุฃุบูุจ ุงูุนู ููุงุช.
- ูู ุงูุณูุฑูุฑ ููุน = ุงูุดุบู ููู ุจููู.
๐ณ Distributed (Git, Mercurial)
- ูู ุฌูุงุฒ ุจูุจูู ุนููู ูุณุฎุฉ ูุงู ูุฉ ู ู ุงูุฑูุจู.
- ุฃุบูุจ ุงูุนู ููุงุช local โ ู ุด ู ุญุชุงุฌ ูุช ุนุดุงู ุชุดุชุบู.
- ุงูุณูุฑูุฑ ู ุฌุฑุฏ ููุทุฉ ุนุดุงู ูุนู ู sync ููุฌู ุน ุงูุดุบู.
- ูู ุงูุณูุฑูุฑ ููุนุ ุงููุงุณ ุชูุฏุฑ ุชูู ู ุดุบู ุนุงุฏู ูููุฏุฑ ูุฑุฌุนู ู ู ุฃู ูุณุฎุฉ.
- ููุญุฏู (Solo): ุนูู ุฌูุงุฒู ุจุณ ูุนูุฏู local repo ูุดุบุงู ู ุน ููุณู.
- ู ุน ุชูู (Team): ุฃุฌูุฒุฉ ูุชูุฑ + ุณูุฑูุฑ (ุฒู GitHub ุฃู GitLab). ููู ุฌูุงุฒ ุนููู ูุณุฎุฉ ูุงู ูุฉ ู ู ุงูุฑูุจู.
The 3 Local Areas โญ
ุนูุฏู ุงูุชูุงุชุฉ ุฏูู: Working Directory ู Staging Area ู Git Directory. ูู ุง ุฏูู ููุจ ูุนุตุจ ุงูู Git.
Working Directory
ุฏู ุงูู ูุงู ุงููู ุจุชุนุฏู ููู ุงููุงููุงุช. ุงููุงููุงุช ููุง ู ู ูู ุชุจูู untrackedุ ุฃู modifiedุ ุฃู unmodified.
Staging Area
ุฏู ุงูู ูุงู ุงููู ุงููุงููุงุช ุจุชุชุฌูุฒ ููู ููู commit ุงูุฌุงู. ุชุนุชุจุฑ ููุทุฉ (Snapshot) ู ุณุชููุฉ ุงูุญูุธ.
Git Directory
ุงูู
ูุงู ุงููู ุงูู Git ุจูุฎุฒู ููู ุงูููุณุชูุฑู ูุงูููู
ูุชุณ (ุงููู ูู ูููุฏุฑ .git).
Operations between areas
| From โ To | Command |
|---|---|
| Git Directory โ Working Directory | git checkout the project |
| Working Directory โ Staging Area | git add file |
| Staging Area โ Git Directory | git commit |
File Status Lifecycle โญ
Every file Git knows about is in one of 4 states.
โ remove the file sends unmodified files back to untracked
ุงูู Git ู
ูุนุฑูุด ุญุงุฌุฉ ุนู ุงููุงูู ุฏู. ูุงูู ุฌุฏูุฏ ุฃู ู
ูุณูุฎ ูู
ุชุนู
ููุด add ุฎุงูุต.
ุนุดุงู ุชุฎููู ูุชุชุจุน: git add filename
ุงูู Git ุนุงุฑููุ ูู ุชุบูุฑุด ู ู ุขุฎุฑ commit. ูุนูู ูุธูู ูู ููููุด ุชุนุฏููุงุช ุฌุฏูุฏุฉ.
ุงูู Git ุนุงุฑููุ ุจุณ ุฅูุช ุนุฏูุช ููู ุจุนุฏ ุขุฎุฑ commitุ ููุณู ุงูุชุนุฏููุงุช ุฏู ู ุฏุฎูุชุด ุงูู Staging Area.
ูุงูู ุฅุชุนุฏู ูุงุชุนู
ูู git add. ุฌุงูุฒ ูู
ุณุชูู ูุฏุฎู ูู ุงูู commit ุงูุฌุงู.
Local Git Commands
Complete cheat sheet for local repo operations.
-a = stage all tracked changes (not new files). -m =
message inline. Common: git commit -a -m "msg".Branches โญ
ู ุณุงุฑุงุช ุชุทููุฑ ู ุณุชููุฉ. ุฏู ุจูู ุงูู killer feature ุจุชุงุนุฉ ุงูู Git ุงููู ู ูุณุฑุฉ ุงูุฏููุง.
ุงูุนูุงู ุฉ ุงููุฌู ุฉ (*) ุฏู ู ุนูุงูุง ุงูู branch ุงููู ุฅูุช ูุงูู ุนููู ุญุงููุงู.
- Feature Branches โ develop new features in isolation.
- Release Branches โ prepare a release.
- Hotfix Branches โ urgent production fixes.
Merge Conflicts
ูู ุง ูุชุบูุฑ ููุณ ุงูุณุทุฑ ูู ุฃูุชุฑ ู ู branchุ ููุง ุจูุญุตู ุงูู conflict ูุจุชุถุฑุจ ู ููุง.
When Git can't auto-merge, it leaves conflict markers in the file like:
<<<<<<< HEAD
Conflicting change from current branch
=======
Conflicting change from incoming branch
>>>>>>> bugfix-branch
- ุงูุชุญ (Open) ุงููุงูู ุงููู ููู ุงูู conflict.
- ุนุฏููู (Edit) ุจุฅูุฏู: ุงุฎุชุงุฑ ุชุณูุจ ุฅูู ูุชู ุณุญ ุฅููุ ุฃู ุชุฏู ุฌูู ู ุน ุจุนุถ.
- ุงู
ุณุญ (Remove) ุงูุนูุงู
ุงุช ุฏู
<<<,===,>>>. - ุงุนู
ูู Stage:
git add filename - ุงุนู
ูู Commit:
git commit -m "resolved"
Full Workflow Example
ู ุณุงุฑ ูุงู ู ููู Git ู ู ุงูุจุฏุงูุฉ ููููุงูุฉ: init โ commit โ branch โ merge โ conflict โ resolve.
1. Initialize
2. Initial commit on master
3. Create and switch to feature branch
4. Merge feature back to master
5. Modify both branches โ create conflict
6. Resolve conflict and finalize
git log โ Viewing History
Many flags for different views.
| Flag | ุงูุงุณุชุฎุฏุงู (Purpose) |
|---|---|
git log |
ุงูุงูุชุฑุงุถู: ุจูุนุฑุถ ูู ุจูุงูุงุช ุงูู commitุ ูุงูุฌุฏูุฏ ุงูุฃูู |
--pretty=short |
ุนุฑุถ ู ุฎุชุตุฑ (ุงููุงุดุ ุงูู ุคููุ ูุงูู ูุถูุน ุจุณ) |
--pretty=full |
ุนุฑุถ ูุงู ู (ุงูู ุคููุ ุงูููู ูุชุฑุ ูุงูุฑุณุงูุฉ ูุงู ูุฉ) |
--pretty=reference |
ุจูุนุฑุถ ุจุตูุบุฉ ู ุฑุฌุนูุฉ (Reference format) |
-3 |
ุขุฎุฑ 3 ููู ูุชุณ ุจุณ |
--oneline |
ุณุทุฑ ูุงุญุฏ ููู ููู ูุช (ุงููุงุด + ุงูุฑุณุงูุฉ) |
--graph |
ุจูุฑุณู ุดูู ุชูุถูุญู ููู branches |
--decorate |
ุจูุถูู ุฃุณุงู ู ุงูู branches ูุงูู tags |
--all |
ุจูุนุฑุถ ุงูููู ูุชุณ ู ู ูู ุงูู branches |
git log --oneline
git log --decorate
git log --graph --oneline --all
ุฃุฏูุงุช ุฒู Ungit ุจุชุฏููู ูุงุฌูุฉ ุจุตุฑูุฉ ููู ูุถูุน ุฏู โ ุดุฌุฑุฉ ููู ูุชุณ ุชูุงุนููุฉ (interactive commit tree).
Remote Repos โ GitHub & GitLab
Shared projects, issue tracking, collaboration.
ุฃูุจุฑ ู ูุตุฉ ูุงุณุชุถุงูุฉ ุงูููุฏ. ุชุจุน ุดุฑูุฉ Microsoft.
- ุฑูุจูุฒ ุนุงู ุฉ ูุฎุงุตุฉ ุจุจูุงุด.
- ุจูููุฑ ู ูุฒุงุช ุฒู Issues ู Pull Requests.
- ููู GitHub Actions ููู (CI/CD).
- ููู Marketplace ู GitHub Pages.
ู ู ูู ุชุณุทุจู ุนูุฏู (Self-hostable) ุฃู ุชุณุชุฎุฏู ู Cloud. ุจูููุฑ ุจุงูุฏุฌ ูุงู ูุฉ ููู DevOps.
- ุงูู CI/CD pipelines ู ุชูุงู ูุฉ ุฌูุงู.
- ููู Issues ู Merge Requests.
- ู ู ูู ุชุณุทุจู ุนูู ุงูุณูุฑูุฑ ุจุชุงุนู (Self-hosting).
- ููู Container registry ู ุจูู ุฌูุงู.
Clone existing remote repo
Push to remote
Pull latest changes
- Issues โ ุนุดุงู ูุชุงุจุน ุงูู bugsุ ูุทูุจ features ุฌุฏูุฏุฉุ ููุชูุงูุด.
- Pull Requests (ูู GitHub) / Merge Requests (ูู GitLab) โ ุชุบููุฑุงุช ููุฏ ู ูุชุฑุญุฉ ูู ุนุงูุง ู ุฑุงุฌุนุฉ (review).
- Code Review โ ุชุนูููุงุชุ ู ูุงููุงุชุ ูุชุบููุฑุงุช ู ูุชุฑุญุฉ ู ู ุงูุชูู .
- Labels & Milestones โ ุนุดุงู ููุธู ุงูุดุบู.
Practice Quiz โ Lecture 18
8 ุฃุณุฆูุฉ ุนูู Git mechanics, file lifecycle, branches, conflicts, remote.
git add ุจูููู ุงููุงููุงุช ูููุง.
git add. ุจูุจุฏุฃ Untracked โ (ุจุนุฏ ุงูู add) โ ุจูุจูู
Unmodified.
git checkout -b feature do?-b ู
ุนูุงูุง "ุงูุฑูุช branch ุฌุฏูุฏ". ูุงูู checkout ุจุชูููู ููู. ุงูุงุชููู ู
ุน ุจุนุถ =
ููุฑูุช ูููููู ุนููู ูู ุฎุทูุฉ ูุงุญุฏุฉ.
<<</===/>>>ุ ุจุชุนู
ูู stage ูุจุนุฏูู commit. ุงูู commit
ุฏู ูู ุงููู ุจููููุด ุงูู merge.
--graph ุนุดุงู ุชุดูู ุงูู treeุ ู --oneline ุนุดุงู ุชุฎูููุง ู
ุฎุชุตุฑุฉุ ู
--all ุนุดุงู ุชุฌูุจ ูู ุงูู branches. ุฏู ุฃูุชุฑ ุชุดูููุฉ ุจุชููุนู.
clone ุจููุฒู ูุณุฎุฉ ูุงู
ูุฉ ู
ู ุงูู remote repo ููููุฏุฑ ุฌุฏูุฏ ุนูุฏู. ุงูู init ุจููุฑูุช
repo ูุงุถู ุฌุฏูุฏ. ูุงูู pull ุจูุณุญุจ ุงูุชุญุฏูุซุงุช ูู ุฑูุจู ู
ุนู
ููู clone ุฃุตูุงู.