Skip to main content

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

git clone 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

ActionEquivalent Manual Steps
Creates the directorymkdir my-project && cd my-project
Initializes Gitgit init
Adds the remotegit remote add origin <url>
Fetches all branchesgit fetch --all
Checks out the default branchgit 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
SymbolMeaning
??Untracked (new file)
AAdded to staging
M (left column)Modified and staged
M (right column)Modified but NOT staged
DDeleted
RRenamed
MMModified, staged, then modified again

Decision Guide

What You WantCommand
Start a brand-new projectgit init
Download an existing projectgit clone <url>
See what files changedgit status
Quick status checkgit status -s
Clone without full historygit clone --depth 1 <url>
Clone to a specific foldergit clone <url> <folder>

Troubleshooting

ProblemCauseFix
fatal: not a git repositoryNot inside a .git/ tracked foldercd to your repo, or run git init
Permission denied (publickey)SSH key not configuredSee SSH Setup
Clone is very slowLarge repository with full historyUse --depth 1 for shallow clone
already exists and is not emptyTarget directory has filesChoose a different name or delete the directory

Best Practices

  • Run git status before every add and commit — know what you're committing
  • Use git clone with SSH (not HTTPS) for repos you'll push to
  • Use --depth 1 for large repos you only need to build, not contribute to
  • Initialize with git init + README.md + .gitignore immediately

What's Next

  1. add, commit & diff — Stage changes and create snapshots
  2. log & history — Navigate your commit history