What you'll build
You'll create your first Git repository and learn the basic version control workflow. You'll understand commits as "saves" of your code that you can recover at any time. You'll push your project to GitHub so you never lose your work, even if your computer fails. This is the foundation of version control that all professional developers around the world use.
Step 1: Install Git
| System | Command |
|---|---|
| macOS | brew install git or comes preinstalled |
| Windows | Download from git-scm.com |
| Linux | sudo apt install git |
Verify:
git --version
Step 2: Configure your identity
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
Step 3: Create a local repository
# Create a folder for your project
mkdir my-project
cd my-project
# Initialize Git
git init
# Create a file
echo "# My Project" > README.md
Step 4: Create .gitignore (CRITICAL!)
โ ๏ธ ALWAYS create
.gitignoreBEFORE the first commit
# Create the .gitignore file
cat > .gitignore << 'EOF'
# Secrets - NEVER upload
.env
.env.local
*.env
credentials.json
*.pem
*.key
# Dependencies
node_modules/
venv/
# Build
dist/
build/
# System
.DS_Store
EOF
Why is it so important?
| Without .gitignore | With .gitignore |
|---|---|
Upload .env with API keys | Automatically protected |
| AI can commit secrets | Git always ignores them |
| Your credentials on public GitHub | Safe on your machine |
Step 5: Your first commit
# Add files to "staging"
git add .
# Save the state (commit)
git commit -m "First commit with .gitignore"
You saved your first state!
Step 6: Create repository on GitHub
- Go to github.com/new
- Name:
my-project - Leave it public or private
- DON'T check "Initialize with README"
- Click Create repository
Step 7: Connect and push
GitHub will show you commands. Copy and run:
git remote add origin https://github.com/YOUR-USERNAME/my-project.git
git branch -M main
git push -u origin main
Did it work?
Refresh the GitHub page. You should see your README.md
Basic Git flow
# 1. You make changes to your files
# 2. You add the changes
git add .
# 3. You save the state
git commit -m "Description of change"
# 4. You push to GitHub
git push
Useful commands
| Command | What it does |
|---|---|
git status | See what changed |
git log | See commit history |
git diff | See differences |
git pull | Download changes from GitHub |
If something failed
| Error | Cause | Solution |
|---|---|---|
not a git repository | No .git | Run git init |
Authentication failed | Wrong credentials | Use GitHub personal token |
rejected non-fast-forward | Remote changes exist | git pull first |
๐ค Tip: Checkpoints before using AI
If you use Cursor, Claude Code or another AI assistant:
# BEFORE asking the AI for something
git add . && git commit -m "Checkpoint before AI changes"
# If the AI breaks something, you can easily revert
git reset --hard HEAD
AI is powerful but sometimes misunderstands. Git is your safety net.
Next step
โ My Dotfiles Setup โ Customize your environment
๐ I want to learn more
โ Git & GitHub (Full Theory) โ Concepts, branches, .gitignore and more