How repositories are born
For Git to track changes, the project directory must become a repository. In essence there are two paths: initialize Git in a local folder (git init) or get an existing project from a remote server along with history (git clone).
Option 1: git init (from scratch)
Use this when the project first appears on your machine — empty or with files already sketched — Git adds versioning via the .git directory.
Creating a repository step by step ▼
bash
1
mkdir my-project && cd my-project
▼
2
git init
▼
3
git branch -M main
▼
What appears in the directory after git init? ▼
структура проекта
📁my-project/▼
⚙️.git/▼
📄script.js▼
Option 2: git clone (copying)
If the repository already exists on GitHub, GitLab, or another host, you do not need to build history by hand: clone downloads objects and sets up the remote origin so you can fetch and push later.
How data gets to your machine ▶
🌐
URL
Use HTTPS or SSH from the repo page
→
📥
Clone
git clone <url> — download and unpack objects
→
📂
Local
A directory with working files and .git appears on disk
→
🔗
Remote
origin points at the source URL — ready to sync
Which should you choose?
git init vs git clone
🆕
git init
📥
git clone
git clone examples ▼
bash
1
git clone https://github.com/user/repository.git
▼
2
git clone https://link.git my-folder-name
▼
⚠️Do not run git init inside a directory that is already a repository (there is already a .git). You get a nested repository and confusion with commits and tools — either work in one repo or add a submodule on purpose.