Initializing a Repository
A Git repository (repo) is a folder tracked by Git. You create one with git init or clone an existing one.
Example
# Create a new project
mkdir my-project
cd my-project
# Initialize Git repository
git init
# Check status
git status
# Output: On branch main, No commits yet The .gitignore File
The .gitignore file tells Git which files and folders to ignore. This is essential for keeping sensitive data and build artifacts out of your repo.
Example
# .gitignore example
# Dependencies
node_modules/
vendor/
# Environment files
.env
.env.local
# Build output
dist/
build/
# OS files
.DS_Store
Thumbs.db
# IDE files
.vscode/
.idea/ Your First Commit
A commit is a snapshot of your project at a point in time. Each commit has a unique ID, author, date, and message.
Example
# Create a file
echo "# My Project" > README.md
# Stage the file
git add README.md
# Commit with a message
git commit -m "Initial commit: add README"
# View commit history
git log
# Shows commit hash, author, date, and message 