Skip to main content

Initialize and Clone Projects

The first step to use Git is to "connect" a project (a folder on your computer) to the version control system. You have two ways to do this: starting a new project from scratch, or downloading one that already exists.

1. Start from Scratch: git init

Imagine you created a new folder for your webpage. Currently it is just a normal folder in your operating system. For Git to start watching it, you must initialize it.

Open the terminal inside your folder and run:

git init

What happened? Git just created a hidden folder called .git inside your directory. Do not delete it or modify it manually! That folder contains the entire "brain" and the version history of your project. Your folder is now officially a local Git Repository.

2. Download an existing project: git clone

Very often you will join a team that already has a project started, hosted in the cloud (for example, on GitHub or GitLab). To bring that project to your computer with all its history intact, you do not download a .zip, you make a clone.

The command requires the remote repository's URL.

# Example: Clone a public repository
git clone https://github.com/user/project-name.git

What happened?

  1. Git automatically created a folder called project-name.
  2. It downloaded absolutely all the code files and folders.
  3. It downloaded the hidden .git folder (meaning, the complete history of who did what and when).
  4. It automatically configured the remote connection, so that later you can push your own changes.

Important: When using git clone, you do not need to run git init. The cloned repository already comes initialized.


Verify the status

Once you are inside a Git repository (initialized or cloned), the command you will use the most in your career is:

git status

This command will tell you exactly what is happening right now: what branch you are on, what files you have modified, what new files you have created, and what remains to be saved. Use it constantly!