๐ŸŒณ Lecture 18 ยท Git mechanics & collaboration

Git Deep Dive

ุฏูŠ ุชูƒู…ู„ุฉ ู„ู€ Lec 17 ูŠุง ุฑูŠุณ. ู‡ู†ุง ู‡ู†ุดูˆู ุงู„ู€ distributed modelุŒ ูˆุงู„ู€ file lifecycleุŒ ูˆุญูˆุงุฑุงุช ุงู„ู€ branchesุŒ ูˆุฅุฒุงูŠ ู†ุญู„ ุงู„ู€ merge conflictsุŒ ูˆุฃู†ูˆุงุน ุงู„ู€ logุŒ ูˆูƒู…ุงู† ุงู„ู€ remote repos. ุดุบู„ ุนู…ู„ูŠ ู…ู† ุงู„ุขุฎุฑ.

9
Chapters
4
File States
3
Git Areas
8
Practice Qs
01

Git's Distributed Model

Every developer has the FULL repository. Many operations are local.

๐ŸŒ Centralized vs Distributed

๐Ÿ›๏ธ Centralized (SVN, CVS, Perforce)

  • ุณูŠุฑูุฑ ูˆุงุญุฏ ู…ุฑูƒุฒูŠ ุจูŠุฎุฒู† ูƒู„ ุงู„ู†ุณุฎ.
  • ุงู„ู€ Clients ุจูŠุงุฎุฏูˆุง ู†ุณุฎุฉ ูŠุดุชุบู„ูˆุง ุนู„ูŠู‡ุง (check out).
  • ู„ุงุฒู… ู†ุช (Network) ุนุดุงู† ุฃุบู„ุจ ุงู„ุนู…ู„ูŠุงุช.
  • ู„ูˆ ุงู„ุณูŠุฑูุฑ ูˆู‚ุน = ุงู„ุดุบู„ ูƒู„ู‡ ุจูŠู‚ู.

๐ŸŒณ Distributed (Git, Mercurial)

  • ูƒู„ ุฌู‡ุงุฒ ุจูŠุจู‚ู‰ ุนู„ูŠู‡ ู†ุณุฎุฉ ูƒุงู…ู„ุฉ ู…ู† ุงู„ุฑูŠุจูˆ.
  • ุฃุบู„ุจ ุงู„ุนู…ู„ูŠุงุช local โ€” ู…ุด ู…ุญุชุงุฌ ู†ุช ุนุดุงู† ุชุดุชุบู„.
  • ุงู„ุณูŠุฑูุฑ ู…ุฌุฑุฏ ู†ู‚ุทุฉ ุนุดุงู† ู†ุนู…ู„ sync ูˆู†ุฌู…ุน ุงู„ุดุบู„.
  • ู„ูˆ ุงู„ุณูŠุฑูุฑ ูˆู‚ุนุŒ ุงู„ู†ุงุณ ุชู‚ุฏุฑ ุชูƒู…ู„ ุดุบู„ ุนุงุฏูŠ ูˆู†ู‚ุฏุฑ ู†ุฑุฌุนู‡ ู…ู† ุฃูŠ ู†ุณุฎุฉ.
๐ŸŽฏ 2 Ways to Use Git
  1. ู„ูˆุญุฏูƒ (Solo): ุนู„ู‰ ุฌู‡ุงุฒูƒ ุจุณ ูˆุนู†ุฏูƒ local repo ูˆุดุบุงู„ ู…ุน ู†ูุณูƒ.
  2. ู…ุน ุชูŠู… (Team): ุฃุฌู‡ุฒุฉ ูƒุชูŠุฑ + ุณูŠุฑูุฑ (ุฒูŠ GitHub ุฃูˆ GitLab). ูˆูƒู„ ุฌู‡ุงุฒ ุนู„ูŠู‡ ู†ุณุฎุฉ ูƒุงู…ู„ุฉ ู…ู† ุงู„ุฑูŠุจูˆ.
โš ๏ธ NoteGitHub for personal projects is great, but for some academic work it might be restricted (e.g., to avoid making coursework public).
02

The 3 Local Areas โญ

ุนู†ุฏูƒ ุงู„ุชู„ุงุชุฉ ุฏูˆู„: Working Directory ูˆ Staging Area ูˆ Git Directory. ู‡ู…ุง ุฏูˆู„ ู‚ู„ุจ ูˆุนุตุจ ุงู„ู€ Git.

๐Ÿ“ The 3 Areas
"Working Tree"

Working Directory

ุฏู‡ ุงู„ู…ูƒุงู† ุงู„ู„ูŠ ุจุชุนุฏู„ ููŠู‡ ุงู„ูุงูŠู„ุงุช. ุงู„ูุงูŠู„ุงุช ู‡ู†ุง ู…ู…ูƒู† ุชุจู‚ู‰ untrackedุŒ ุฃูˆ modifiedุŒ ุฃูˆ unmodified.

"Index"

Staging Area

ุฏู‡ ุงู„ู…ูƒุงู† ุงู„ู„ูŠ ุงู„ูุงูŠู„ุงุช ุจุชุชุฌู‡ุฒ ููŠู‡ ู„ู„ู€ commit ุงู„ุฌุงูŠ. ุชุนุชุจุฑ ู„ู‚ุทุฉ (Snapshot) ู…ุณุชู†ูŠุฉ ุงู„ุญูุธ.

"Repository"

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
03

File Status Lifecycle โญ

Every file Git knows about is in one of 4 states.

๐Ÿ”„ The 4 States
untracked
add the file
unmodified
edit the file
modified
stage the file
staged
โ† commit sends staged files back to unmodified
โ† remove the file sends unmodified files back to untracked
โ“ Untracked

ุงู„ู€ Git ู…ูŠุนุฑูุด ุญุงุฌุฉ ุนู† ุงู„ูุงูŠู„ ุฏู‡. ูุงูŠู„ ุฌุฏูŠุฏ ุฃูˆ ู…ู†ุณูˆุฎ ูˆู…ุชุนู…ู„ูˆุด add ุฎุงู„ุต.

ุนุดุงู† ุชุฎู„ูŠู‡ ูŠุชุชุจุน: git add filename

โœ… Unmodified

ุงู„ู€ Git ุนุงุฑูู‡ุŒ ูˆู…ุชุบูŠุฑุด ู…ู† ุขุฎุฑ commit. ูŠุนู†ูŠ ู†ุธูŠู ูˆู…ููŠู‡ูˆุด ุชุนุฏูŠู„ุงุช ุฌุฏูŠุฏุฉ.

โœ๏ธ Modified

ุงู„ู€ Git ุนุงุฑูู‡ุŒ ุจุณ ุฅู†ุช ุนุฏู„ุช ููŠู‡ ุจุนุฏ ุขุฎุฑ commitุŒ ูˆู„ุณู‡ ุงู„ุชุนุฏูŠู„ุงุช ุฏูŠ ู…ุฏุฎู„ุชุด ุงู„ู€ Staging Area.

๐Ÿ“ฆ Staged

ูุงูŠู„ ุฅุชุนุฏู„ ูˆุงุชุนู…ู„ู‡ git add. ุฌุงู‡ุฒ ูˆู…ุณุชู†ูŠ ูŠุฏุฎู„ ููŠ ุงู„ู€ commit ุงู„ุฌุงูŠ.

04

Local Git Commands

Complete cheat sheet for local repo operations.

โŒจ๏ธ Setup & Status
$ mkdir site $ cd site $ git init Initialized empty Git repository in /home/user/site/.git/ $ ls -R .git branches/ config HEAD hooks/ info/ objects/ refs/ $ git status On branch master No commits yet nothing to commit (create/copy files and use "git add" to track)
๐Ÿ“ Staging Files
$ echo "hello" > myfile $ git status Untracked files: myfile $ git add myfile $ git status Changes to be committed: new file: myfile // To UN-stage a file: $ git rm --cached myfile
๐Ÿ’พ Committing
// Add all + commit in one step: $ git commit -a -m "my commit message" // First-time identity: $ git config --global user.name "Your Name" $ git config --global user.email "you@example.com" // Amend (modify) the LAST commit: $ git commit --amend
๐Ÿ’ก -a vs -am-a = stage all tracked changes (not new files). -m = message inline. Common: git commit -a -m "msg".
05

Branches โญ

ู…ุณุงุฑุงุช ุชุทูˆูŠุฑ ู…ุณุชู‚ู„ุฉ. ุฏูŠ ุจู‚ู‰ ุงู„ู€ killer feature ุจุชุงุนุฉ ุงู„ู€ Git ุงู„ู„ูŠ ู…ูƒุณุฑุฉ ุงู„ุฏู†ูŠุง.

๐ŸŒฟ Creating Branches
$ git branch b1 b2 * master
๐ŸŒฟ ุฅู†ุดุงุก ุงู„ู€ Branches
$ git branch b1 b2 * master $ git branch b3 # ุจุชุนู…ู„ ุจุฑุงู†ุด ุฌุฏูŠุฏ $ git branch b1 b2 b3 * master

ุงู„ุนู„ุงู…ุฉ ุงู„ู†ุฌู…ุฉ (*) ุฏูŠ ู…ุนู†ุงู‡ุง ุงู„ู€ branch ุงู„ู„ูŠ ุฅู†ุช ูˆุงู‚ู ุนู„ูŠู‡ ุญุงู„ูŠุงู‹.

๐Ÿ”€ ุงู„ุชู†ู‚ู„ ุจูŠู† ุงู„ู€ Branches
$ git checkout b1 Switched to branch 'b1' $ git branch -l * b1 master // Create + switch in one command: $ git checkout -b feature-branch Switched to a new branch 'feature-branch'
๐Ÿ”— Merging Branches
// Switch to TARGET (the branch you merge INTO) $ git checkout master // Merge the source branch into it $ git merge feature-branch Updating 46cc7e3..3a4af86 Fast-forward file.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) // Delete branch after merge $ git branch -d feature-branch
๐Ÿ’ก Fast-Forward MergeIf the target branch hasn't moved since the source branch was created, Git just "fast-forwards" the pointer. No new commit needed.
๐Ÿ“‚ Branch Strategies
  • Feature Branches โ€” develop new features in isolation.
  • Release Branches โ€” prepare a release.
  • Hotfix Branches โ€” urgent production fixes.
06

Merge Conflicts

ู„ู…ุง ูŠุชุบูŠุฑ ู†ูุณ ุงู„ุณุทุฑ ููŠ ุฃูƒุชุฑ ู…ู† branchุŒ ู‡ู†ุง ุจูŠุญุตู„ ุงู„ู€ conflict ูˆุจุชุถุฑุจ ู…ู†ู†ุง.

โš ๏ธ Detecting a Conflict
$ git checkout b3 readme2.txt: needs merge error: you need to resolve your current index first

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
๐Ÿ› ๏ธ Resolving Conflicts
  1. ุงูุชุญ (Open) ุงู„ูุงูŠู„ ุงู„ู„ูŠ ููŠู‡ ุงู„ู€ conflict.
  2. ุนุฏู‘ู„ู‡ (Edit) ุจุฅูŠุฏูƒ: ุงุฎุชุงุฑ ุชุณูŠุจ ุฅูŠู‡ ูˆุชู…ุณุญ ุฅูŠู‡ุŒ ุฃูˆ ุชุฏู…ุฌู‡ู… ู…ุน ุจุนุถ.
  3. ุงู…ุณุญ (Remove) ุงู„ุนู„ุงู…ุงุช ุฏูŠ <<<, ===, >>>.
  4. ุงุนู…ู„ู‡ Stage: git add filename
  5. ุงุนู…ู„ู‡ Commit: git commit -m "resolved"
$ # after editing the file $ git add file.txt $ git commit -m "Resolve conflict and merge bugfix-branch"
07

Full Workflow Example

ู…ุณุงุฑ ูƒุงู…ู„ ู„ู„ู€ Git ู…ู† ุงู„ุจุฏุงูŠุฉ ู„ู„ู†ู‡ุงูŠุฉ: init โ†’ commit โ†’ branch โ†’ merge โ†’ conflict โ†’ resolve.

๐ŸŽฌ Step-by-Step Sequence

1. Initialize

$ git init my-repo $ cd my-repo

2. Initial commit on master

$ echo "Initial Commit" > file.txt $ git add file.txt $ git commit -m "Initial commit" $ git log

3. Create and switch to feature branch

$ git checkout -b feature-branch $ echo "Feature Work" > feature.txt $ git add feature.txt $ git commit -m "Add feature work"

4. Merge feature back to master

$ git checkout master $ git merge feature-branch

5. Modify both branches โ†’ create conflict

$ echo "Hotfix in main" >> file.txt $ git commit -a -m "Apply hotfix" $ git checkout -b bugfix-branch $ echo "Bugfix Work" > file.txt $ git commit -a -m "Add bugfix work" $ git checkout master $ echo "Conflicting Change" >> file.txt $ git commit -a -m "Conflicting change in main" $ git merge bugfix-branch CONFLICT: Merge conflict in file.txt

6. Resolve conflict and finalize

# (edit file.txt manually, remove markers) $ git add file.txt $ git commit -m "Resolve conflict and merge bugfix-branch" $ git log --oneline --graph
08

git log โ€” Viewing History

Many flags for different views.

๐Ÿ“œ Common Flags
Flag ุงู„ุงุณุชุฎุฏุงู… (Purpose)
git log ุงู„ุงูุชุฑุงุถูŠ: ุจูŠุนุฑุถ ูƒู„ ุจูŠุงู†ุงุช ุงู„ู€ commitุŒ ูˆุงู„ุฌุฏูŠุฏ ุงู„ุฃูˆู„
--pretty=short ุนุฑุถ ู…ุฎุชุตุฑ (ุงู„ู‡ุงุดุŒ ุงู„ู…ุคู„ูุŒ ูˆุงู„ู…ูˆุถูˆุน ุจุณ)
--pretty=full ุนุฑุถ ูƒุงู…ู„ (ุงู„ู…ุคู„ูุŒ ุงู„ูƒูˆู…ูŠุชุฑุŒ ูˆุงู„ุฑุณุงู„ุฉ ูƒุงู…ู„ุฉ)
--pretty=reference ุจูŠุนุฑุถ ุจุตูŠุบุฉ ู…ุฑุฌุนูŠุฉ (Reference format)
-3 ุขุฎุฑ 3 ูƒูˆู…ูŠุชุณ ุจุณ
--oneline ุณุทุฑ ูˆุงุญุฏ ู„ูƒู„ ูƒูˆู…ูŠุช (ุงู„ู‡ุงุด + ุงู„ุฑุณุงู„ุฉ)
--graph ุจูŠุฑุณู… ุดูƒู„ ุชูˆุถูŠุญูŠ ู„ู„ู€ branches
--decorate ุจูŠุถูŠู ุฃุณุงู…ูŠ ุงู„ู€ branches ูˆุงู„ู€ tags
--all ุจูŠุนุฑุถ ุงู„ูƒูˆู…ูŠุชุณ ู…ู† ูƒู„ ุงู„ู€ branches
๐ŸŽจ Examples

git log --oneline

1234abc Commit message 1 5678def Commit message 2 9abc123 Commit message 3

git log --decorate

* 1234abc (HEAD -> master, origin/master) Commit message * 5678def (feature) Commit message

git log --graph --oneline --all

* 3a4af86 (HEAD -> master) Resolve conflict |\ | * 46cc7e3 (bugfix-branch) Add bugfix * | b7e2310 Hotfix in main |/ * 9abc123 Initial commit

ุฃุฏูˆุงุช ุฒูŠ Ungit ุจุชุฏูŠู„ูƒ ูˆุงุฌู‡ุฉ ุจุตุฑูŠุฉ ู„ู„ู…ูˆุถูˆุน ุฏู‡ โ€” ุดุฌุฑุฉ ูƒูˆู…ูŠุชุณ ุชูุงุนู„ูŠุฉ (interactive commit tree).

09

Remote Repos โ€” GitHub & GitLab

Shared projects, issue tracking, collaboration.

๐Ÿ™ GitHub

ุฃูƒุจุฑ ู…ู†ุตุฉ ู„ุงุณุชุถุงูุฉ ุงู„ูƒูˆุฏ. ุชุจุน ุดุฑูƒุฉ Microsoft.

  • ุฑูŠุจูˆุฒ ุนุงู…ุฉ ูˆุฎุงุตุฉ ุจุจู„ุงุด.
  • ุจูŠูˆูุฑ ู…ูŠุฒุงุช ุฒูŠ Issues ูˆ Pull Requests.
  • ููŠู‡ GitHub Actions ู„ู„ู€ (CI/CD).
  • ููŠู‡ Marketplace ูˆ GitHub Pages.
๐ŸฆŠ GitLab

ู…ู…ูƒู† ุชุณุทุจู‡ ุนู†ุฏูƒ (Self-hostable) ุฃูˆ ุชุณุชุฎุฏู…ู‡ Cloud. ุจูŠูˆูุฑ ุจุงูƒุฏุฌ ูƒุงู…ู„ุฉ ู„ู„ู€ DevOps.

  • ุงู„ู€ CI/CD pipelines ู…ุชูƒุงู…ู„ุฉ ุฌูˆุงู‡.
  • ููŠู‡ Issues ูˆ Merge Requests.
  • ู…ู…ูƒู† ุชุณุทุจู‡ ุนู„ู‰ ุงู„ุณูŠุฑูุฑ ุจุชุงุนูƒ (Self-hosting).
  • ููŠู‡ Container registry ู…ุจู†ูŠ ุฌูˆุงู‡.
๐Ÿงฑ Common Remote Operations

Clone existing remote repo

$ git clone https://github.com/user/repo.git

Push to remote

# Standard workflow $ git branch new-branch $ git checkout new-branch # ...make changes, then: $ git add . $ git commit -m "Add new feature" $ git checkout master $ git merge new-branch $ git push

Pull latest changes

$ git pull // Fetches and merges remote changes into your current branch
๐ŸŽซ Issues & Collaboration
  • 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.

Question 1 Practice โ€” distributed
Which is the main difference between Centralized and Distributed VCS?
A Distributed is more secure
B Centralized supports branches; Distributed doesn't
C In Distributed, every machine has a full copy of the repository
D Distributed requires more disk space than Centralized (it doesn't)
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: C ูƒู„ client ู„ู„ู€ Git ุจูŠุจู‚ู‰ ุนู†ุฏู‡ ู†ุณุฎุฉ ูƒุงู…ู„ุฉ = ูู…ุนุธู… ุงู„ุฃูˆุงู…ุฑ ุจุชุดุชุบู„ local. ุงู„ู€ Centralized ุจูŠุญุชุงุฌ ุณูŠุฑูุฑ ุนุดุงู† ูƒู„ ุญุงุฌุฉ ุชู‚ุฑูŠุจุงู‹.
Question 2 Practice โ€” areas
In Git, what is the Staging Area?
A Where final commits are stored permanently
B A snapshot of changes prepared for the next commit (also called the "Index")
C Where you edit files
D The remote repository
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: B ุงู„ู€ Staging Area (ุฃูˆ ุงู„ู€ Index) ุฏูŠ ุงู„ู„ูŠ ุจุชุดูŠู„ ุงู„ูุงูŠู„ุงุช ุงู„ู„ูŠ ุฌุงู‡ุฒุฉ ูŠุญุตู„ู‡ุง commit. ุงู„ู€ git add ุจูŠู†ู‚ู„ ุงู„ูุงูŠู„ุงุช ู„ูŠู‡ุง.
Question 3 Practice โ€” lifecycle
A file you just created but never added to Git is in which state?
A Modified
B Untracked
C Staged
D Unmodified
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: B โ€” Untracked ุงู„ู€ Git ู…ูŠุนุฑูุด ุญุงุฌุฉ ุนู† ุงู„ูุงูŠู„ ู„ุญุฏ ู…ุง ุชุนู…ู„ู‡ git add. ุจูŠุจุฏุฃ Untracked โ†’ (ุจุนุฏ ุงู„ู€ add) โ†’ ุจูŠุจู‚ู‰ Unmodified.
Question 4 Practice โ€” branches
What does git checkout -b feature do?
A Lists all branches
B Deletes a branch
C Creates a new branch AND switches to it
D Renames a branch
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: C ุงู„ู€ -b ู…ุนู†ุงู‡ุง "ุงูƒุฑูŠุช branch ุฌุฏูŠุฏ". ูˆุงู„ู€ checkout ุจุชู†ู‚ู„ูƒ ู„ูŠู‡. ุงู„ุงุชู†ูŠู† ู…ุน ุจุนุถ = ูŠูƒุฑูŠุช ูˆูŠู†ู‚ู„ูƒ ุนู„ูŠู‡ ููŠ ุฎุทูˆุฉ ูˆุงุญุฏุฉ.
Question 5 Practice โ€” conflicts
After resolving a merge conflict, what is the correct next step?
A Revert the merge
B Run git merge again
C Push immediately without committing
D git add the resolved file, then git commit
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: D ุจุนุฏ ู…ุง ุชุธุจุท ุงู„ูุงูŠู„ ุงู„ู„ูŠ ููŠู‡ ุงู„ู€ conflict ูˆุชู…ุณุญ ุงู„ุนู„ุงู…ุงุช ุฏูŠ <<</===/>>>ุŒ ุจุชุนู…ู„ู‡ stage ูˆุจุนุฏูŠู† commit. ุงู„ู€ commit ุฏู‡ ู‡ูˆ ุงู„ู„ูŠ ุจูŠูู†ู‘ุด ุงู„ู€ merge.
Question 6 Practice โ€” git log
Which flag shows commits from all branches in a visual graph with one-line summaries?
A --pretty=full
B --oneline
C --graph
D --graph --oneline --all
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: D ุงุฌู…ุนู‡ู… ู…ุน ุจุนุถ: --graph ุนุดุงู† ุชุดูˆู ุงู„ู€ treeุŒ ูˆ --oneline ุนุดุงู† ุชุฎู„ูŠู‡ุง ู…ุฎุชุตุฑุฉุŒ ูˆ --all ุนุดุงู† ุชุฌูŠุจ ูƒู„ ุงู„ู€ branches. ุฏูŠ ุฃูƒุชุฑ ุชุดูƒูŠู„ุฉ ุจุชู†ูุนูƒ.
Question 7 Practice โ€” remote
To download an existing remote repository to your machine, you use:
A git init
B git clone <url>
C git pull
D git checkout <url>
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: B โ€” git clone ุงู„ู€ clone ุจูŠู†ุฒู„ ู†ุณุฎุฉ ูƒุงู…ู„ุฉ ู…ู† ุงู„ู€ remote repo ู„ููˆู„ุฏุฑ ุฌุฏูŠุฏ ุนู†ุฏูƒ. ุงู„ู€ init ุจูŠูƒุฑูŠุช repo ูุงุถูŠ ุฌุฏูŠุฏ. ูˆุงู„ู€ pull ุจูŠุณุญุจ ุงู„ุชุญุฏูŠุซุงุช ููŠ ุฑูŠุจูˆ ู…ุนู…ูˆู„ู‡ clone ุฃุตู„ุงู‹.
Question 8 Practice โ€” fast-forward
A fast-forward merge happens when:
A The target branch hasn't moved since the source branch was created โ€” Git just moves the pointer forward
B A merge results in a conflict
C You force push to a remote
D Two branches have diverged commits
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: A ู…ููŠุด merge commit ุฌุฏูŠุฏ ุจูŠุชูƒุฑูŠุช โ€” ุงู„ู€ pointer ุจุชุงุน ุงู„ู€ target branch ู…ุฌุฑุฏ ุฅู†ู‡ ุจูŠู…ุดูŠ ู„ู‚ุฏุงู… (fast-forwards) ู„ุญุฏ ุขุฎุฑ ุชุญุฏูŠุซ ููŠ ุงู„ู€ source branch. ุฏู‡ ุจูŠู†ูุน ุจุณ ู„ูˆ ุงู„ู€ target ู…ููŠุด ููŠู‡ ุฃูŠ commits ุฌุฏูŠุฏุฉ.
๐Ÿ“‹

Cheat Sheet

๐Ÿ“ 3 Git Areas

Working Dir
ุงู„ู…ูƒุงู† ุงู„ู„ูŠ ุจุชุนุฏู„ ููŠู‡ ุงู„ูุงูŠู„ุงุช
Staging (Index)
ูุงูŠู„ุงุช ุฌุงู‡ุฒุฉ ู„ู„ู€ commit ุงู„ุฌุงูŠ
Git Dir (Repo)
ููˆู„ุฏุฑ .git ูˆุงู„ู‡ูŠุณุชูˆุฑูŠ ูƒู„ู‡

๐Ÿ”„ 4 File States

Untracked
Git ู„ุณู‡ ู…ูŠุนุฑููˆุด ุฎุงู„ุต
Unmodified
ู†ุธูŠู ูˆู…ุทุงุจู‚ ู„ุขุฎุฑ commit
Modified
ุงุชุนุฏู„ ุจุณ ู„ุณู‡ ู…ุงุชุนู…ู„ูˆุด add
Staged
ุงุชุนู…ู„ู‡ add ูˆุฌุงู‡ุฒ ู„ู„ู€ commit

๐ŸŒฟ Branch Commands

git branch
ูŠุนุฑุถ ุงู„ู€ branches (* = ุงู„ุญุงู„ูŠ)
git branch <name>
ูŠูƒุฑูŠุช branch ุฌุฏูŠุฏ
git checkout <n>
ูŠุฑูˆุญ ู„ู€ branch ุชุงู†ูŠ
git checkout -b <n>
ูŠูƒุฑูŠุช ูˆูŠุฑูˆุญู„ู‡ ููŠ ู†ูุณ ุงู„ูˆู‚ุช
git merge <n>
ูŠุฏู…ุฌ branch ู…ุน ุงู„ู„ูŠ ุฅู†ุช ูˆุงู‚ู ุนู„ูŠู‡
git branch -d <n>
ูŠู…ุณุญ branch ุจุนุฏ ู…ุง ุงู†ุฏู…ุฌ

โš”๏ธ Conflict Resolution

Step 1
ุงูุชุญ ุงู„ูุงูŠู„ ุงู„ู…ุถุฑูˆุจ
Step 2
ุนุฏู„ู‡ ูˆุงู…ุณุญ ุนู„ุงู…ุงุช <<< === >>>
Step 3
git add ู„ู„ูุงูŠู„ ุงู„ู…ุชุตู„ุญ
Step 4
git commit ุนุดุงู† ุชูู†ุด ุงู„ู€ merge

๐Ÿ“œ git log Flags

--oneline
ูƒู„ commit ููŠ ุณุทุฑ ูˆุงุญุฏ ู…ุฎุชุตุฑ
--graph
ุจูŠุฑุณู… ุงู„ู€ branches ูƒุดุฌุฑุฉ
--all
ุจูŠุฌูŠุจ ู…ู† ูƒู„ ุงู„ู€ branches
--decorate
ุจูŠุนุฑุถ ุฃุณุงู…ูŠ ุงู„ู€ branches ูˆุงู„ู€ tags
-N
ุจูŠุนุฑุถ ุขุฎุฑ N ูƒูˆู…ูŠุชุณ
ุชุดูƒูŠู„ุฉ ุงู„ุฏู…ุงุฑ
--graph --oneline --all

๐ŸŒ Remote Commands

git clone <url>
ุจูŠู†ุฒู„ ู†ุณุฎุฉ ู…ู† ุฑูŠุจูˆ ุฃูˆู†ู„ุงูŠู†
git push
ุจูŠุฑูุน ุงู„ูƒูˆู…ูŠุชุณ ุจุชุงุนุชูƒ ู„ู„ุณูŠุฑูุฑ
git pull
ุจูŠุณุญุจ ุงู„ุฌุฏูŠุฏ ูˆูŠุฏู…ุฌู‡ ุนู†ุฏูƒ
git fetch
ุจูŠู†ุฒู„ ุงู„ุฏุงุชุง ุจุณ ู…ู† ุบูŠุฑ ู…ุง ูŠุฏู…ุฌ
GitHub
ุงุณู…ู‡ ููŠู‡ Pull Requests
GitLab
ุงุณู…ู‡ ููŠู‡ Merge Requests