Why Version Control, and Your First Repository
Git records snapshots of your project over time. With it you can see what changed, when and why; undo mistakes; work on several ideas at once; and collaborate without emailing zip files. Every professional software team uses it.
One-time setup
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait" # or nano, vim
The three areas
| Area | What it is |
|---|---|
| Working directory | the files you edit |
| Staging area (index) | changes you have chosen for the next commit |
| Repository | the saved history of commits (the .git folder) |
You edit files, stage the changes you want with git add, then commit them with a message. Staging lets you split unrelated edits into separate, clear commits.
Your first repository
mkdir hello-git && cd hello-git
git init
echo "# Hello Git" > README.md
git status # README.md is untracked
git add README.md
git status # staged, ready to commit
git commit -m "Add README"
git log --oneline # a1b2c3d Add README
The everyday loop
git status # what changed?
git diff # exact changes not yet staged
git add app.py # stage one file
git add -p # stage piece by piece (review each change)
git diff --staged # what will be committed
git commit -m "Validate email on signup"
git add -p is the habit that separates careful developers from everyone else: you review every line before it enters history.
Writing good commit messages
- Start with a short summary in the imperative: "Fix login redirect", not "fixed stuff".
- Keep the summary under about 60 characters.
- If more is needed, leave a blank line, then explain why the change was made.
Limit contact form to 5 posts per hour
Bots were sending hundreds of messages a day. The limit and the
honeypot field stop them without affecting real visitors.
.gitignore: what never to commit
Create .gitignore before your first commit:
.env
.venv/
__pycache__/
*.db
node_modules/
uploads/
Never commit secrets. If a key reaches a public repository, assume bots have already copied it: revoke and rotate it immediately. Deleting the file in a new commit does not remove it from history.
Practice
In the Practice Terminal, complete the First commit mission: git init, git add readme.txt, git commit -m "first commit".
Check yourself
- What is the staging area for?
- Which file stops
.envfrom being committed? - What should you do if you pushed an API key?
Tu progreso se guarda solo en este navegador.
Enviar para revisión (10 puntos)