Books/Git Essentials/Your First Repository

    Your First Repository

    Your First Repository

    A repository (or "repo") is simply a project folder that Git is tracking. Let's create one.

    Two Ways to Start

    There are two ways to get a Git repository:

    MethodWhen to Use
    git initStarting a brand new project from scratch
    git cloneCopying an existing project from GitHub

    Method 1: git init (New Project)

    Create a new project folder and initialize Git:

    # Create a new folder
    mkdir my-first-project
    cd my-first-project
    
    # Initialize Git
    git init

    You'll see:

    Initialized empty Git repository in /path/to/my-first-project/.git/
    

    That's it! Your folder is now a Git repository. Let's add a file:

    # Create a simple file
    echo "# My First Project" > README.md

    Method 2: git clone (Existing Project)

    If a project already exists on GitHub, you can clone it:

    git clone https://github.com/username/repository-name.git

    This downloads the entire project — all files and all history — to your computer.

    # After cloning, move into the project folder
    cd repository-name

    What to ask your AI: "I found a GitHub repository at [URL]. Can you help me clone it and explore the project structure?"

    The .git Folder

    After running git init or git clone, you'll notice a hidden .git folder:

    ls -la
    drwxr-xr-x  .git
    -rw-r--r--  README.md
    

    The .git folder is where Git stores everything — all your history, branches, and configuration. Here's what you need to know:

    • Never delete or edit the .git folder manually
    • If you delete .git, you lose all your Git history
    • It's automatically hidden (starts with a dot)

    Think of .git as Git's brain for your project. Leave it alone and let Git manage it.

    Checking Your Repository Status

    The most useful command you'll learn is:

    git status

    Right after creating a new repo with a README, you'll see:

    On branch main
    
    No commits yet
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    	README.md
    
    nothing added to commit but untracked files present (use "git add" to track)
    

    This tells you:

    • You're on the main branch
    • You haven't saved any snapshots (commits) yet
    • Git sees README.md but isn't tracking it yet ("untracked")

    What to ask your AI: "I ran git status and I see [paste output]. Can you explain what each line means?"

    A Practical Example

    Let's put it all together — create a project, add some files, and check the status:

    # Create and enter a new project
    mkdir hello-git
    cd hello-git
    git init
    
    # Create a few files
    echo "# Hello Git" > README.md
    echo "console.log('hello!');" > app.js
    echo "node_modules/" > .gitignore
    
    # Check what Git sees
    git status

    Output:

    On branch main
    
    No commits yet
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    	.gitignore
    	README.md
    	app.js
    

    Git sees all three files but isn't tracking them yet. In the next tutorial, we'll learn how to track and save these changes.

    The .gitignore File

    Notice we created a .gitignore file. This tells Git which files to ignore (not track). Common things to ignore:

    # Dependencies
    node_modules/
    
    # Environment variables (secrets!)
    .env
    
    # Build output
    dist/
    build/
    
    # OS files
    .DS_Store
    Thumbs.db
    

    What to ask your AI: "I'm building a [React/Python/etc] project. Can you generate a .gitignore file for me?"

    What's Next?

    You have a Git repository with some files. The next tutorial will teach you how to track changes — adding files and creating your first commit.


    🌐 www.genai-mentor.ai