← Back to Mission Control

Initiating Your Launch Sequence

10 min read

Initializing a Git Repository

Mission Phase 8 • Difficulty: Beginner

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:

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:

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

  1. Create a directory: mkdir git-practice
  2. Enter it: cd git-practice
  3. Initialize Git: git init
  4. Create a README: echo "# Git Practice" > README.md
  5. Verify: ls -la (you should see .git)

When NOT to Initialize

Don't run git init in:

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.