What is the difference between git init and git clone?
git init turns the current folder into a new, empty repository. git clone copies an existing repository, including its full history, from a URL, and also sets up the origin remote for you.
Explain it simply
git init is like buying a fresh notebook; git clone is photocopying someone else's entire notebook, every page and every edit.
With init, Git creates a hidden .git folder in your project and starts tracking from nothing. There is no remote, so to share it you add one yourself with git remote add. With clone, Git downloads all commits and branches, creates a folder, checks out the default branch, and records the source URL as origin so push and pull work straight away.
Use init for a project you are starting; use clone to join one that already exists on GitHub.
Example
mkdir blog && cd blog
git init # new empty repo
git remote add origin https://github.com/me/blog.git
git clone https://github.com/me/blog.git # copy existing repo
cd blog && git remote -v # origin already setWhat to say in the interview
"git init creates a new empty repository in the current directory with no remote. git clone copies an existing repository with its whole history, checks out the default branch and configures origin. I init for new projects and clone to work on existing ones."
Common mistakes
- Running git init inside a cloned folder, which makes a nested repository.