SyntaxStudy
Sign Up
Git git init, git clone, and .gitignore
Git Beginner 9 min read

git init, git clone, and .gitignore

Start tracking a project with git init, or get a copy of an existing repository with git clone. A .gitignore file tells Git which files and directories to ignore — essential for keeping secrets, build artifacts, and OS files out of your repository.

Example
# Start a new repository:
mkdir my-project && cd my-project
git init
# Creates a .git folder — the repository database

# Clone an existing repository:
git clone https://github.com/user/repo.git
git clone https://github.com/user/repo.git my-folder  # custom folder name
git clone git@github.com:user/repo.git                # via SSH

# .gitignore — patterns of files to ignore:
# node_modules/
# dist/
# build/
# .env
# .env.local
# *.log
# *.tmp
# .DS_Store          (macOS)
# Thumbs.db          (Windows)
# .idea/             (IntelliJ)
# .vscode/settings.json

# gitignore.io generates templates for your stack:
# https://www.toptal.com/developers/gitignore

# Tell Git to stop tracking an already-committed file:
git rm --cached .env
echo ".env" >> .gitignore
git commit -m "Stop tracking .env"