Every Git project begins in one of two ways: either you start a brand-new project locally using git init, or you download an existing codebase from a remote hosting platform like GitHub using git clone. Let's master both operations.
git initThe git init command transforms an ordinary operating system directory into a fully functioning, version-controlled Git repository by creating a hidden .git folder in its root.
# Step 1: Create a new project directory and enter it
$ mkdir my-veewom-app
$ cd my-veewom-app
# Step 2: Initialize Git in the current directory
$ git init
Initialized empty Git repository in G:/Programming/my-veewom-app/.git/
You can also initialize a new folder in a single command by passing the directory name:
$ git init my-awesome-project
.git/?Running git init creates the skeleton directory structure that Git uses to track everything:
$ ls -la .git/
drwxr-xr-x 1 user staff 160 Nov 8 07:00 hooks/ # Sample client/server hook scripts
drwxr-xr-x 1 user staff 160 Nov 8 07:00 info/ # Repository info & exclude file
drwxr-xr-x 1 user staff 160 Nov 8 07:00 objects/ # Database of all blobs, trees, commits
drwxr-xr-x 1 user staff 160 Nov 8 07:00 refs/ # Branch heads and release tags
-rw-r--r-- 1 user staff 23 Nov 8 07:00 HEAD # Points to refs/heads/main
-rw-r--r-- 1 user staff 130 Nov 8 07:00 config # Local repo configuration
git cloneIf a project already exists on GitHub, GitLab, or Bitbucket, you do not use git init. Instead, you clone it using git clone [url].
Unlike other version control tools (like SVN checkout), git clone does not merely copy the latest version of the code. It downloads every single commit, branch, and tag that has ever occurred in the project's history!
# Clone via HTTPS:
$ git clone https://github.com/torvalds/linux.git
# Clone via SSH (Recommended for authenticated developers):
$ git clone git@github.com:facebook/react.git
# Clone into a custom folder name:
$ git clone https://github.com/expressjs/express.git my-custom-express-folder
--depth 1When working on massive codebases (like the Linux kernel, Chromium, or Kubernetes) that have 15+ years of history and gigabytes of commits, cloning full history can consume hours and massive bandwidth. If you only need to build or inspect the latest code, perform a shallow clone:
# Clones ONLY the most recent commit, saving 90%+ download time and disk space:
$ git clone --depth 1 https://github.com/angular/angular.git
--single-branch# Clones only the 'main' branch, ignoring dozens of other remote feature branches:
$ git clone -b main --single-branch https://github.com/user/project.git
If a repository depends on nested external repositories (submodules), pass the recursive flag so Git initializes and pulls them automatically:
$ git clone --recurse-submodules https://github.com/company/super-project.git
Question: "What is the difference between git init and git clone?"
Answer: "git init is used to create a brand-new, empty Git repository from scratch locally on your machine. git clone is used to copy an existing repository from a remote location (like GitHub), which downloads all history, branches, tags, and automatically configures a remote origin pointer."
Open your terminal right now, navigate to your temporary directory, create a folder named git-test, run git init, and inspect the created .git folder using ls -a (or dir /a on Windows CMD).
Strengthen your version control mastery by studying these connected classes:
Craft clean atomic commits with meaningful conventional commit messages.
Link local repositories to GitHub remotes using git remote add origin.
Initialize public or private remote repositories with README, license, and ignore files.
Monitor untracked files with git status and review log streams with git log.
Advance your software engineering skills with the next topic in our synchronized curriculum.
Continue to Staging & Commits → Previous: ← Three-Tree Architecture | Full Syllabus