02. Git Repo Folder - ivomac/GitBasics GitHub Wiki
🪣 Git Repository
The Git Repository is usually found in the .git/ folder inside the root project folder:
.git/
├── HEAD # 🧭 Current position
├── config # ⚙️ Settings
├── hooks/ # 🪝 Event scripts
├── index # 📋 Index
├── logs/ # 📜 History logs
├── objects/ # 💾 Database of all versions of files (compressed)
│ ├── 8d/
│ │ └── 629a6f...
│ └── ...
└── refs/
├── heads/ # 👉 Branches
│ ├── main
│ └── feature-x
└── tags/ # 🏷️ Tags
👉 Branches
A branch is simply a file in .git/refs/heads/ that contains the commit hash it points to. For example:
# .git/refs/heads/main:
8d629a6ffc1e5e3a0346681bb7576bowc3e9a0f
🧭 HEAD
HEAD is the special pointer that registers which commit/branch you're currently on:
# .git/HEAD:
ref: refs/heads/main
This means you're on the main branch.
📋 Index
- .git/index contains references to changes you have staged for inclusion in the next commit.
- Whatever you stage is saved in .git/objects and referenced by hash in the index.
- 🔑 index $\leftrightarrow$ .git/index $\leftrightarrow$ Draft of the next commit you are working on.
- You can stage:
- New files.
- All changes in an already tracked file.
- Only some of the changes within a file.
- 🧩 A changed segment within a file is called a hunk.
- ✨ If you stage a new file, then delete it, you can still commit the file!
🌲 Staging Hunks
- Go to "File Status" tab.
- Double-click on a file to view its changes.
- Stage segments of changes with "Stage hunk" or "Stage this line".
📸 Commits
When you commit, Git:
- Creates a new commit object in .git/objects using .git/index.
- If we are at a branch, updates the current branch pointer to the new commit.
- 🔒 Commit objects are immutable: To make any changes to a commit, a new commit with a new hash must be created to replace the previous one.