C.W.K.
Stream
Lesson 01 of 05 · published

git init vs git clone

~16 min · init, clone

Level 0Untracked Rookie
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

init from scratch, clone from elsewhere

Two ways to get a Git repository on disk: bring history with you (git clone), or start a fresh history (git init). They look superficially similar — both produce a .git/ folder — but the consequences are different. Knowing which one you want is the start of the daily loop.

git init creates an empty repository in the current directory. No commits, no branches that exist yet (until you make the first commit), no remotes. The default branch name comes from init.defaultBranch (set this to main globally; the old default master is unmaintained-Linux baggage). After git init you typically write a starter .gitignore, run git add ., and make the first commit so the project's history actually begins.

git clone downloads an existing repository. By default it copies all branches as remote-tracking refs (origin/main, origin/feature, etc.), checks out the default branch, and sets up a remote called origin that points at the URL you cloned. SSH URLs (git@github.com:user/repo.git) avoid daily password prompts; HTTPS URLs (https://github.com/user/repo.git) work everywhere including locked-down corporate networks but require a token or credential helper.

For huge repos, two clone tricks are worth knowing. --depth 1 does a shallow clone — only the most recent commit, no history. Fast, but you cannot blame or bisect usefully. --filter=blob:none does a partial clone — it grabs the commit graph and tree structure immediately, then fetches blobs lazily as you check them out. Modern, faster than shallow for most workflows, and Git 2.20+.

Code

Brand-new project — init flow·bash
mkdir new-thing && cd new-thing
git init
echo '.env' >> .gitignore
echo 'node_modules/' >> .gitignore
git add .gitignore
git commit -m "Add starter .gitignore"
git log --oneline    # one commit
Existing project — clone flow·bash
# SSH (preferred for daily dev):
git clone git@github.com:org/repo.git

# HTTPS (firewalled networks, CI):
git clone https://github.com/org/repo.git

# Clone into a custom folder name:
git clone git@github.com:org/repo.git my-folder

# Shallow (fast, no full history):
git clone --depth 1 https://github.com/org/big-repo.git

# Partial (lazy blob fetch — better than shallow for most cases):
git clone --filter=blob:none https://github.com/org/big-repo.git

External links

Exercise

Pick one tiny side project of yours that lives in a folder without Git, run git init, write a real .gitignore, commit. Then on a different machine or directory, git clone a public repo using both an SSH URL (if you have keys) and an HTTPS URL. Compare what git remote -v shows in each case. Write one sentence on when you would pick init versus clone.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.