Creating a Repository

Turn any folder into a Git repository with git init.

Syntaxgit init

A repository (or repo) is a project folder that Git is tracking. Run git init inside a folder to start tracking it.

What happens

Git creates a hidden .git directory that stores the entire history and configuration. The rest of your files stay exactly as they were. Deleting .git would remove version control but keep your files.

Two ways to start

  • git init — start a brand new repo from a local folder.
  • git clone — copy an existing repo (covered later).

Example

Example · bash
mkdir my-project
cd my-project
git init
# Initialized empty Git repository in my-project/.git/

When to use it

  • A freelancer turns their existing project folder into a Git repo before pushing it to GitHub for the first time.
  • A data scientist initialises a new repo for a machine-learning experiment so every model iteration is tracked.
  • A team lead creates a bare repository on a shared server to act as a central push target for the whole team.

More examples

Initialise a new project repo

Creates the hidden .git directory that turns a plain folder into a fully functional Git repository.

Example · bash
mkdir my-project && cd my-project
git init
# Initialized empty Git repository in .../my-project/.git/

Init and make first commit

Follows the minimal workflow: initialise, create one file, stage it, and record the very first snapshot.

Example · bash
git init
echo '# My Project' > README.md
git add README.md
git commit -m "Initial commit"

Create a bare repo for sharing

A bare repo has no working tree; it is used purely as a shared push/pull target, similar to what GitHub hosts internally.

Example · bash
# On the server
git init --bare /srv/repos/my-project.git

# On a developer machine
git remote add origin ssh://server/srv/repos/my-project.git
git push -u origin main

Discussion

  • Be the first to comment on this lesson.