๐Ÿ“š

My First Repository

๐Ÿง‘โ€๐ŸŽ“ Apprenticeโฑ๏ธ 15 minutes

๐Ÿ“‹ Suggested prerequisites

  • โ€ขHello World in Terminal completed
  • โ€ขGitHub account

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

SystemCommand
macOSbrew install git or comes preinstalled
WindowsDownload from git-scm.com
Linuxsudo 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 .gitignore BEFORE 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 .gitignoreWith .gitignore
Upload .env with API keysAutomatically protected
AI can commit secretsGit always ignores them
Your credentials on public GitHubSafe 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

  1. Go to github.com/new
  2. Name: my-project
  3. Leave it public or private
  4. DON'T check "Initialize with README"
  5. 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

CommandWhat it does
git statusSee what changed
git logSee commit history
git diffSee differences
git pullDownload changes from GitHub

If something failed

ErrorCauseSolution
not a git repositoryNo .gitRun git init
Authentication failedWrong credentialsUse GitHub personal token
rejected non-fast-forwardRemote changes existgit 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