๐Ÿ“š

Git & GitHub

๐Ÿง‘โ€๐ŸŽ“ Apprentice

Why from your first project?

"It's just a tiny project, I don't need Git..."

Wrong. Use Git from day 1, even for a 10-line script. Why?

What you thinkWhat actually happens
"It's too simple"It grows more than expected
"I'll remember everything"In 2 weeks you won't remember why you changed something
"I have backup on Drive"Drive doesn't tell you what changed between versions
"I'll set it up later""Later" never comes, and when you need it, it's too late

๐Ÿค– Git saves you from AI

This is critical if you use code assistants like Cursor, Claude Code, or Copilot:

SituationWithout GitWith Git
AI misunderstood your prompt and deleted important code๐Ÿ˜ฑ Lostgit checkout -- .
The agent "improved" something that worked and now it won't compile๐Ÿ˜ฑ Rewrite itgit diff to see what changed
You asked for a small change and it modified 15 files๐Ÿ˜ฑ Chaosgit stash and start over
After 5 prompts, everything is worse than before๐Ÿ˜ฑ Frustrationgit reset --hard HEAD~5

โš ๏ธ Reality: AI agents are powerful but make mistakes. An ambiguous prompt can result in destructive changes. Git is your safety net.

Recommended workflow with AI:

# BEFORE asking the AI for something
git add . && git commit -m "Checkpoint before AI changes"

# If the AI breaks something
git diff                    # See what changed
git checkout -- file.js     # Revert one file
git reset --hard HEAD       # Revert EVERYTHING to last commit

Our recommendation: git init is the FIRST command in any project. Before writing code, before installing dependencies. Git first.


Git โ‰  GitHub: The fundamental difference

Before looking at commands, understand this:

GitGitHub
What is it?Software on your computerWebsite / cloud service
Where does it live?Local (your machine)Remote (internet)
Who created it?Linus Torvalds (2005)Microsoft (acquired 2018)
Cost?Free, open sourceFree + paid plans
Do they need each other?Git works without GitHubGitHub needs Git

Analogy: Git is your personal journal where you write every day. GitHub is the bank's safety deposit box where you keep a copy.


What are they really for?

Git (local) allows you to:

UseExample
๐Ÿ“ธ Complete historySee exactly what changed, when, and why
โช Go back in time"It worked yesterday, what did I break today?"
๐Ÿ”€ Experiment fearlesslyCreate branches to try crazy ideas
๐Ÿ” Find bugs"Which commit introduced this error?"
๐Ÿ“ Document decisionsCommit messages are documentation

GitHub (remote) allows you to:

UseExample
โ˜๏ธ Cloud backupIf your laptop gets stolen, your code is safe
๐Ÿ‘ฅ CollaborateMultiple devs working on the same project
๐Ÿ” Code reviewPull Requests to review before merging
๐ŸŒ PortfolioYour profile shows your activity and projects
๐Ÿš€ Auto deployGitHub Actions, Vercel, etc.

When do you only need Git?

โœ… Git alone is enough when:

  • You work solo on your machine
  • The project is personal/experimental
  • You don't need remote backup (but you should...)
  • You're learning

When do you need GitHub?

โœ… Add GitHub when:

  • You want backup (always recommended!)
  • You work in a team
  • The project is open source
  • You want to showcase your work (portfolio)
  • You need CI/CD (automated tests, deploy)

Real scenario: Your laptop gets stolen ๐Ÿ’ป๐Ÿ”“

SituationWithout GitHubWith GitHub
Your codeLost forevergit clone and continue
HistoryLostIntact in the cloud
Time lostWeeks/months of work5 minutes to clone

Moral: Local Git + remote GitHub = peace of mind.


Installation

SystemCommand
macOSbrew install git
Linuxsudo apt install git
Windowswinget install Git.Git

Initial setup

# Identity (appears in every commit)
git config --global user.name "Your Name"
git config --global user.email "your@email.com"

# Default branch
git config --global init.defaultBranch main

# Editor for long messages
git config --global core.editor "code --wait"

Key concepts

ConceptWhat it isAnalogy
RepositoryFolder with Git historyPhoto album
CommitSnapshot of current stateDated photo in album
BranchAlternative development lineDraft of a chapter
MergeJoin two branchesIntegrate draft into book
RemoteConnection to GitHub/GitLabCloud copy
CloneDownload remote repoCopy album from bank
PushUpload commits to remoteTake new photos to bank
PullDownload commits from remoteGet photos others uploaded

Workflow

Git only (local)

# Create repository
git init my-project
cd my-project

# Work...
echo "# My Project" > README.md

# See what changed
git status

# Add to staging
git add README.md    # specific file
git add .            # all changes

# Create commit
git commit -m "Initial: add README"

# View history
git log --oneline

Git + GitHub (local + remote)

# Connect to GitHub (once)
git remote add origin https://github.com/your-user/your-repo.git

# Push your code
git push -u origin main

# After each work session:
git add .
git commit -m "Describe what you did"
git push

Branches: Experiment fearlessly

# Create branch for new feature
git checkout -b feature/login

# Work on the feature...
git add .
git commit -m "Add login form"

# Go back to main
git checkout main

# Integrate the feature
git merge feature/login

# Delete branch (no longer needed)
git branch -d feature/login

GitHub CLI (gh)

# Install
brew install gh

# Authenticate (opens browser)
gh auth login

# Clone repo
gh repo clone user/repo

# Create repo from current folder
gh repo create my-project --public --source=.

# Create Pull Request
gh pr create --fill

Emergency commands

# "I messed up, I want to go back to last commit"
git checkout -- .

# "I want to see how it was 3 commits ago"
git checkout HEAD~3

# "Who wrote this line?"
git blame file.js

# "Which commit broke it?"
git bisect start
git bisect bad          # current is bad
git bisect good abc123  # this commit was good
# Git finds the culprit automatically

Visual summary

    YOUR COMPUTER                           GITHUB (CLOUD)
    โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                           โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    ๐Ÿ“ Working Directory
         โ”‚
         โ”‚ git add
         โ–ผ
    ๐Ÿ“ฆ Staging Area
         โ”‚
         โ”‚ git commit
         โ–ผ
    ๐Ÿ“š Local Repository  โ”€โ”€โ”€โ”€ git push โ”€โ”€โ”€โ–ถ โ˜๏ธ Remote Repository
                         โ—€โ”€โ”€ git pull โ”€โ”€โ”€โ”€

๐Ÿ” .gitignore: Your shield against leaks

The .gitignore file tells Git which files to NEVER track. This is CRITICAL for security.

โš ๏ธ Real danger: AI and your secrets

AI assistants (Cursor, Claude Code, Copilot) can accidentally:

Dangerous situationConsequence
Add .env to commitYour API keys become public
Create file with hardcoded credentialsAnyone can see them on GitHub
"Improve" code by moving secrets to new files.gitignore doesn't cover them

๐Ÿšจ True story: Thousands of AWS API keys leak every day on GitHub. Bots scan public repos looking for credentials. Your account can be hacked within minutes.

Essential .gitignore file

Create this at the root of EVERY project:

# .gitignore

# Environment variables (SECRETS!)
.env
.env.local
.env.*.local
*.env

# Credentials
credentials.json
*-credentials.json
*.pem
*.key
secrets/

# Dependencies (reinstallable)
node_modules/
venv/
__pycache__/

# Build (regeneratable)
dist/
build/
.next/
.output/

# IDE
.vscode/
.idea/
*.swp

# OS
.DS_Store
Thumbs.db

# Logs
*.log
npm-debug.log*

Useful commands

# See what Git is ignoring
git status --ignored

# If you already committed a file with secrets ๐Ÿ˜ฑ
git rm --cached .env
git commit -m "Remove .env from tracking"
# IMPORTANT: The file is still in history!
# Change ALL credentials that were leaked

# Verify before push
git diff --staged   # See what you're about to push

Golden rule

NEVER put credentials directly in code. Use environment variables (.env) and make sure .env is in .gitignore BEFORE the first commit.


๐Ÿ’ผ GitHub as a professional portfolio

Your GitHub profile is more important than you think:

SituationWhat they look at
Job applicationsRecruiters check your GitHub before interviews
FreelancingClients want to see real working projects
Contract bidsCompanies evaluate code quality and documentation

What makes a repo "professional"?

my-project/
โ”œโ”€โ”€ README.md          # โญ CRITICAL: What it does, how to install, screenshots
โ”œโ”€โ”€ LICENSE            # MIT, Apache, etc.
โ”œโ”€โ”€ .gitignore         # Clean, no node_modules or .env
โ”œโ”€โ”€ docs/              # Architecture, technical decisions
โ”‚   โ””โ”€โ”€ ARCHITECTURE.md
โ”œโ”€โ”€ src/               # Organized code
โ”œโ”€โ”€ tests/             # โญ Tests demonstrate professionalism
โ””โ”€โ”€ .github/
    โ””โ”€โ”€ workflows/     # CI/CD shows you know DevOps

Portfolio repo checklist

  • README with clear description and screenshots/GIFs
  • Installation instructions that WORK
  • Tests (even basic ones)
  • Clean code with comments where needed
  • No secrets or credentials (check the history!)
  • Commits with descriptive messages (not "fix", "update")

๐Ÿ’ก Tip: 3-5 well-made public repos impress more than 50 abandoned ones.

Your GitHub profile

Create a repo with your username (e.g., alannreyes/alannreyes) with a README.md that appears on your profile:

# ๐Ÿ‘‹ Hi, I'm [Your Name]

๐Ÿ”ญ Currently working on...
๐ŸŒฑ Learning...
๐Ÿ’ฌ Ask me about...
๐Ÿ“ซ Contact me: your@email.com

๐Ÿณ Practice: Your first repository

Ready to apply all this?

โ†’ My First Repository โ€” Create and push your first repo to GitHub step by step


๐Ÿ“š Next level

โ†’ Advanced Git & Collaboration โ€” PRs, merge conflicts, rebases and teamwork


Useful links