Your First Repository
Every mission begins with preparation. Before your spacecraft can launch, all systems must be initialized. In Git, we call this process "initializing a repository." This transforms an ordinary directory into a version-controlled project.
What is a Repository?
A repository (or "repo") is a directory that Git tracks. It contains:
- Your project files
- A hidden
.gitdirectory storing all version history - Metadata about commits, branches, and configuration
Think of it as your spacecraft's flight recorder—it remembers everything.
Creating Your Project Directory
First, create a directory for your project:
mkdir my-first-mission
cd my-first-mission
You're now in an empty directory, ready to initialize Git.
The Init Command
Transform your directory into a Git repository with one command:
git init
You'll see output like:
Initialized empty Git repository in /path/to/my-first-mission/.git/
That's it! Your repository is initialized.
What Just Happened?
The git init command created a hidden .git directory. This directory contains:
objects/: Stores all committed datarefs/: Stores pointers to commits (branches, tags)HEAD: Points to the current branchconfig: Repository-specific configuration- Various other Git internals
Important: Never manually edit files in .git/. Git manages this directory.
Viewing Hidden Files
To see the .git directory:
ls -la
The -a flag shows hidden files (those starting with .).
Creating Your First File
Let's create a README file for your project:
echo "# My First Mission" > README.md
Or use your text editor to create and edit README.md:
# My First Mission
This is my first Git repository. I'm learning version control!
## Mission Objectives
- Learn Git basics
- Make my first commit
- Push to GitHub
## Status
Mission in progress
Two Ways to Start
Method 1: Start Local, Add Remote Later
What we just did—create a directory, initialize Git, then optionally connect to GitHub later.
Method 2: Clone from GitHub
Create a repository on GitHub first, then clone it to your computer. We'll cover this in detail later.
Both methods work. Choose based on your workflow.
Initial Branch Name
When you initialize a repository, Git creates a default branch. Historically this was called "master," but modern practice uses "main."
If you configured this globally (as recommended earlier), git init creates a "main" branch automatically. If not, you can rename it:
git branch -M main
Practice Exercise
Initialize Your Practice Repository
- Create a directory:
mkdir git-practice - Enter it:
cd git-practice - Initialize Git:
git init - Create a README:
echo "# Git Practice" > README.md - Verify:
ls -la(you should see.git)
When NOT to Initialize
Don't run git init in:
- Your home directory (would track everything!)
- System directories
- Inside another Git repository (creates nested repos—usually bad)
- Directories you don't want version controlled
Checking if Directory is a Repository
To check if you're in a Git repository:
git status
If you see "fatal: not a git repository," you're not in one. If you see status information, you are.
Repository Templates
Advanced users can create template repositories with pre-configured files and settings. For now, simple initialization is perfect.
What's Next?
Your repository is initialized. Your spacecraft is ready for launch. But before we can record changes, you need to understand how Git tracks files. That's where git status comes in.
Launch Sequence Initiated: Your repository is alive. The .git directory is your mission recorder, ready to log every change you make. Time to check your systems status.