Initialize & Clone

So you want to start tracking your project with Git? Great choice! You have two paths forward, depending on whether you’re starting something new or joining an existing project.

Starting Fresh: Initialize a Repository

When you have a folder full of code (or even an empty folder) and you want Git to start tracking it, you’re creating a repository from scratch.

git init

What just happened? This is the moment your folder becomes a time machine for code. Git created a hidden .git directory in your project folder - this is where all the version history, snapshots, and temporal navigation equipment lives. Your actual files stay exactly where they are; Git just starts paying attention to them.

Want to understand what happens under the hood? Check out How Git Works to learn about Git’s internal architecture and what that .git directory contains.

From this point forward, you can:

  • Travel back to any previous version
  • Create alternate timelines (branches) to experiment
  • See exactly what changed and when
  • Undo mistakes by rewinding time

When to use this:

  • You’re starting a brand new project
  • You have existing code that isn’t tracked yet
  • You want to turn “just a folder” into “a Git repository”

Think of git init as flipping the switch that powers up your time machine. The machine is now operational, waiting for you to tell it which moments to save.

Pro Tip: After running git init, your folder looks the same, but Git is now watching. Use ls -la to see the hidden .git directory that appeared - that’s your repository’s brain.


Joining an Existing Project: Clone a Repository

More commonly, you’re not starting from scratch - you’re joining a project that already exists somewhere else (like on GitHub, GitLab, or your company’s server). This is where cloning comes in.

git clone <repository-url>

# Clone into a specific directory name
git clone <repository-url> <directory>

What just happened? Git reached out to that remote repository, copied everything - all the files, all the history, all the branches - and created a complete, independent copy on your computer. You now have the full time machine, not just a snapshot.

When to use this:

  • Joining an existing project
  • Contributing to open source
  • Working with teammates who have a shared repository
  • Creating a backup copy of a repository

Example:

# Clone from GitHub
git clone https://github.com/username/project.git

# Clone into a custom folder name
git clone https://github.com/username/project.git my-project

What’s the difference from downloading a ZIP file? A ZIP gives you just the current files. Cloning gives you the entire history, all branches, and sets up a connection to the original repository so you can sync changes later.


The Key Difference: Init vs Clone

Use git init when you’re building the time machine from scratch - turning a local folder into a Git repository for the first time.

Use git clone when you’re getting a pre-built time machine - copying an existing repository complete with all its history from somewhere else (remote server, GitHub, etc.).

Here’s another way to think about it:

  • git init = “Build a new time machine here”
  • git clone = “Give me a complete copy of that time machine over there”

What Happens Next?

After initializing or cloning, you’re ready to start working. Your next steps will typically be:

  1. Check what’s going on: git status (we’ll cover this in Basic Workflow)
  2. Make changes to your files
  3. Stage changes: git add
  4. Commit changes: git commit

For now, just know that you’ve successfully created or joined a Git repository. You’re in. The time machine is operational.

Curious about what’s inside that .git directory? We dive deep into Git’s internal architecture in the Concepts section. For now, just know it’s there, working quietly in the background.