git init, git clone & git status
Quick Summary
These three commands are where every Git workflow begins: init creates a new repository, clone copies an existing one, and status tells you what's happening right now. Master these and you'll never feel lost in Git.
git init — Create a New Repository
Transforms the current directory into a Git repository by creating the .git/ subdirectory.
Syntax
git init [directory]
Examples
# Initialize in current directory
git init
# Initialize in a new directory (creates the directory too)
git init my-project
Expected output:
Initialized empty Git repository in /home/user/my-project/.git/
What git init Creates
my-project/
└── .git/
├── HEAD
├── config
├── objects/
├── refs/
└── hooks/
When to use
git init- Starting a brand-new project from scratch
- Converting an existing folder into a Git repository
- Creating a bare repository on a server (
git init --bare)
git clone — Copy an Existing Repository
Downloads a complete copy of a remote repository (all branches, tags, and history).
Syntax
git clone <url> [directory]
Examples
- SSH (recommended)
- HTTPS
- Custom directory name
- Shallow clone (faster)
git clone git@github.com:donnyaw/my-project.git
git clone https://github.com/donnyaw/my-project.git
git clone git@github.com:donnyaw/my-project.git my-local-name
# Clone only the latest commit (no history)
git clone --depth 1 git@github.com:donnyaw/my-project.git
Expected output:
Cloning into 'my-project'...
remote: Enumerating objects: 150, done.
remote: Counting objects: 100% (150/150), done.
remote: Compressing objects: 100% (100/100), done.
Receiving objects: 100% (150/150), 50.00 KiB | 500.00 KiB/s, done.
Resolving deltas: 100% (50/50), done.
What git clone Does Automatically
| Action | Equivalent Manual Steps |
|---|---|
| Creates the directory | mkdir my-project && cd my-project |
| Initializes Git | git init |
| Adds the remote | git remote add origin <url> |
| Fetches all branches | git fetch --all |
| Checks out the default branch | git checkout main |
SSH vs HTTPS
SSH is recommended for VPS/developer use — no password prompts, and you authenticate with SSH keys. HTTPS is simpler for one-time clones but requires tokens or passwords for pushing.
git status — Understand Your Repo State
Shows the current state of your working directory and staging area. This is the command you'll run most frequently.
Syntax
git status
git status -s # Short/compact format
git status --ignored # Also show ignored files
Reading the Output
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.md ← Staged (will be in next commit)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
modified: src/app.js ← Modified but not staged
Untracked files:
(use "git add <file>..." to include in what will be committed)
new-feature.js ← New file, not tracked yet
File Lifecycle in Git
stateDiagram-v2
[*] --> Untracked: New file created
Untracked --> Staged: git add
Staged --> Committed: git commit
Committed --> Modified: Edit the file
Modified --> Staged: git add
Staged --> Untracked: git rm --cached
Committed --> [*]: git rm
Short Format (-s)
$ git status -s
M README.md ## Green M = staged
M src/app.js ## Red M = modified (not staged)
?? new-feature.js ## ?? = untracked
A new-file.txt ## A = newly staged
D old-file.txt ## D = deleted
| Symbol | Meaning |
|---|---|
?? | Untracked (new file) |
A | Added to staging |
M (left column) | Modified and staged |
M (right column) | Modified but NOT staged |
D | Deleted |
R | Renamed |
MM | Modified, staged, then modified again |
Decision Guide
| What You Want | Command |
|---|---|
| Start a brand-new project | git init |
| Download an existing project | git clone <url> |
| See what files changed | git status |
| Quick status check | git status -s |
| Clone without full history | git clone --depth 1 <url> |
| Clone to a specific folder | git clone <url> <folder> |
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
fatal: not a git repository | Not inside a .git/ tracked folder | cd to your repo, or run git init |
Permission denied (publickey) | SSH key not configured | See SSH Setup |
| Clone is very slow | Large repository with full history | Use --depth 1 for shallow clone |
already exists and is not empty | Target directory has files | Choose a different name or delete the directory |
Best Practices
- Run
git statusbefore everyaddandcommit— know what you're committing - Use
git clonewith SSH (not HTTPS) for repos you'll push to - Use
--depth 1for large repos you only need to build, not contribute to - Initialize with
git init+README.md+.gitignoreimmediately
What's Next
- add, commit & diff — Stage changes and create snapshots
- log & history — Navigate your commit history