Tutorial 01 — Основы Git
Цель: init, add, commit, status, log, diff. Понять staging area.
Время: ~20 минут
Требования: Git установлен (git --version).
Шаг 1. Настройка (один раз)
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git config --global init.defaultBranch main
git config --global core.editor vim # или code, nanoШаг 2. Создание репозитория
mkdir myproject && cd myproject
git init
# Initialized empty Git repository in /home/user/myproject/.git/
ls -la .git/
# config HEAD hooks/ objects/ refs/Шаг 3. Первый коммит
# Создать файл
echo "# My Project" > README.md
# Статус — что изменилось?
git status
# Untracked files: README.md
# Добавить в staging area
git add README.md
git status
# Changes to be committed: new file: README.md
# Зафиксировать
git commit -m "Initial commit: add README"Шаг 4. Staging Area (индекс)
Working Directory → Staging Area → Repository
(файлы) (git add) (git commit)
# Изменить файл
echo "Description" >> README.md
echo "print('hello')" > app.py
git status
# Changes not staged: README.md
# Untracked: app.py
# Добавить всё
git add .
# Или выборочно
git add README.md
# Посмотреть что в staging
git diff --stagedШаг 5. История
git log
# commit abc123 (HEAD -> main)
# Author: Your Name
# Date: ...
# Initial commit: add README
# Компактный формат
git log --oneline
# abc123 Initial commit: add README
# С графом веток
git log --oneline --graph --all
# Что изменилось в коммите
git show abc123Шаг 6. Diff — что изменилось
# Рабочая директория vs staging
git diff
# Staging vs последний коммит
git diff --staged
# Между коммитами
git diff abc123 def456
# Конкретный файл
git diff README.mdШаг 7. .gitignore
cat > .gitignore << 'EOF'
# Python
__pycache__/
*.pyc
.venv/
# Node
node_modules/
dist/
# IDE
.idea/
.vscode/
# OS
.DS_Store
Thumbs.db
# Environment
.env
*.log
EOF
git add .gitignore
git commit -m "Add .gitignore"Что мы изучили
| Команда | Что делает |
|---|---|
git init | Создать репозиторий |
git add . | Добавить всё в staging |
git commit -m "msg" | Зафиксировать изменения |
git status | Что изменилось |
git log --oneline | История коммитов |
git diff | Различия в файлах |
Что дальше
→ 02-branching — ветки, merge, конфликты