Creating a Repository with git init
You'll learn how to initialize a new Git repository and understand what happens behind the scenes when you do.
What Does git init Do?
When you run git init in a project directory, you're telling Git to start tracking changes in that folder. Think of it like turning a regular notebook into a lab notebook with a built-in time machine—Git begins watching your files and preparing to record their history.
The command creates a hidden .git folder that contains all the infrastructure Git needs to track versions, branches, commits, and metadata about your project.
How to Initialize a Repository
Navigate to your project directory and run:
cd /path/to/your/data-science-project
git init
You'll see a message like: Initialized empty Git repository in /path/to/your/data-science-project/.git/
That's it! Your directory is now a Git repository.
Understanding the .git Folder
The .git folder is where Git stores everything:
- config: repository-specific settings
- objects/: stored versions of your files (as compressed snapshots)
- refs/: pointers to commits (branches and tags)
- HEAD: points to your current branch
- hooks/: scripts that run at specific Git events
You rarely interact with these files directly—Git commands handle them for you. This hidden folder is what makes your directory "version-controlled."
When to Use git init
Use git init when starting a new data science project from scratch. If you're joining an existing project with Git already set up, you'll use git clone instead (covered later).
Key Takeaway: git init transforms an ordinary directory into a Git repository by creating a hidden .git folder that stores all version control metadata—this is your first step toward tracking changes in any new project.