First Repository: init, add, commit, and the Magic of the Index
We'll create our first repository and immediately encounter a concept that many struggle with for years - the staging area (index). We'll explore why this 'intermediate layer' between the working directory and history is essential, and through examples, we'll see how the two-step add → commit system results in meaningful, deliberate commits rather than random ones.
- You'll understand why the staging area exists and how it helps create atomic, meaningful commits.
- You'll be able to create a repository, add files to the index, and make your first commit with a proper message.
- You'll learn how to stage only specific parts of a file using git add -p.
Simula ng leksyon
Creating Your First Repository
- git init creates a hidden .git folder
- .git stores the entire change history
- You can create a repository in any directory
- Existing files become untracked
- Analogy: Starting a new journal in a fresh notebook
Think of your project as a book and the repository as its draft, where every edit is preserved. When you run git init, a hidden .git directory appears in your folder - this is your repository. Inside, Git will store all your change history, metadata, and settings. It's important to understand that you can create a repository at any time, even if the folder already contains files. They'll simply become untracked, and you can add them later. It's like starting a new journal - you have your notebook ready, but you haven't yet decided which entries will make the final cut.
Under the Hood of .git
- objects: compressed file data and commits
- refs: pointers to branches and tags like bookmarks
- HEAD: current position in history
- config: repository settings
- hooks: automation scripts
Let's take a peek inside the .git folder. This is where Git's magic happens. The objects directory stores all your files and commits in compressed form. The refs folder contains pointers to branches and tags - much like bookmarks in a book. The HEAD file shows your current position in the history. And config stores repository-specific settings. There are also hooks - scripts that run automatically during certain events. Git creates all of this automatically during initialization. While you won't need to look here often, understanding this structure will help you navigate more complex situations.
Hands-on: Creating a Repository
- Open terminal in your project folder
- Run git init
- Verify .git creation with ls -la
- Windows: use dir /ah
- Done! Your folder is now version-controlled
Open your terminal in the project directory. Type git init and press Enter. You'll see a message confirming that an empty Git repository has been initialized. To verify everything worked correctly, run the command ls -la — you should see a hidden .git folder. If you're using Windows, use the command dir /ah. Congratulations, your folder is now under version control! Git will be able to track all the changes you make from now on. Now that we've created the repository, it's time to understand how Git classifies files — this is key to understanding how it works.
# Create a project folder and navigate into it
mkdir my_first_repo
cd my_first_repo
# Initialize the repository
git init
# Verify .git creation
ls -la | grep .git
Buong leksyon ay para sa subscription
20 pang slide sa buong bersyon.
Mabubuksan ang video, lahat ng slide, tala, pagsusulit, AI tutor, at interview pagkatapos mag-sign in at mag-subscribe.
Mag-sign in o magparehistro Mag-subscribeNilalaman ng leksyon
- Creating Your First Repository
- Under the Hood of .git
- Hands-on: Creating a Repository
- The Three File States: Why It Matters
- Working Directory: Where the Magic Happens
- The Index: Staging Changes in Meaningful Chunks
- Commit: Preserving History Forever
- The Git Index: A Staging Area for Commits
- Adding a Specific File to the Staging Area
- Adding All Modified Files
- What is a Git Commit?
- Creating Your First Commit
- How to Write Good Commit Messages
- The Problem of Mixed Changes
- Git add -p in Action
- How to Read Patches
- Why Commit Without Add Doesn't Work
- One Task, One Commit
- Commit Messages That Make Sense a Year Later
- Creating Your First Repository
- The Staging Area: Between Code and Commit
- Crafting a Meaningful Commit
- Your First Commit: What's Next?
Mga artikulo tungkol sa araling ito
- git add at git commit: tamang paraan ng pag-save ng pagbabago
- Mga command ng Git: cheat sheet na may mga halimbawa para sa araw-araw
- Git repository: paano gumawa gamit ang git init at ikabit ang remote
- File na .gitignore: paano ibukod ang mga file sa Git at alisin ang nakaraang na-add
- Git at GitHub: ano ang pagkakaiba at paano sila magkaugnay
Lahat ng leksyon ng kurso
- Introduction: Git from Scratch to Confident Developer
- Why Git is Essential - And Why It's a Job Requirement
- Installation and Setup: Getting Git Ready for First Use
- First Repository: init, add, commit, and the Magic of the Index
- Reading History: log, diff, show and Navigating the Past
- Branches: The Parallel Reality of Your Code
- Undoing Mistakes: restore, reset, revert — Doing It Right and the Dangers
- GitHub and Remote Repositories: Your Code in the Cloud
- Team Collaboration: Forks, Feature Branches, and Pull Requests
- Merge Conflicts: Don't Panic - Understanding and Resolving Them
- Git Workflows in Real Teams: Choosing the Right Approach
- Advanced Tools: Rebase, Stash, Cherry-pick and Tags
- Final Project: Simulating Real Team Development