Git module
Demo
First Git shift
Build a small retail analytics mini-repo — gitignore, commits, branch, merge — with optional remote push.
45 minLocal lab
Do this after branches and merge (through lesson 7+). Remotes/GitHub lessons help for the optional stretch.
You will version a tiny analytics project: README, ignore rules, and SQL that matches the retail lab. The website runs nothing.
What you need
- Git identity from Getting Started
- Optional: SQL lab still running if you want to execute the query
1. Scaffold the project
mkdir -p ~/dcubes/git-lab/shift/sql ~/dcubes/git-lab/shift/data/raw
cd ~/dcubes/git-lab/shift
git init
git branch -M main
git status
cat > .gitignore << 'EOF'
.venv/
__pycache__/
.env
data/raw/
data/out/
*.log
.ipynb_checkpoints/
EOF
cat > README.md << 'EOF'
# retail-shift
Practice analytics repo for the DCubes Git demo.
## Layout
- `sql/` — analytic queries for the retail Postgres lab
- `data/raw/` — ignored; keep extracts local
## Run SQL
Point `psql` at your sql-lab database (port 15432) and run files under `sql/`.
EOF
cat > sql/revenue_by_category.sql << 'EOF'
-- Completed revenue by product category
SELECT p.category,
count(*) AS orders,
round(sum(o.line_total), 2) AS revenue
FROM orders o
JOIN products p ON o.sku = p.sku
WHERE o.status = 'completed'
GROUP BY p.category
ORDER BY revenue DESC;
EOF
echo "local dump - do not commit" > data/raw/should_ignore.csv
echo "TOKEN=fake" > .env
2. First commits
git add .gitignore README.md
git commit -m "Add README and gitignore for retail-shift"
git add sql/revenue_by_category.sql
git commit -m "Add revenue_by_category.sql"
git status
git log --oneline
git status should not list .env or data/raw/should_ignore.csv.
3. Feature branch
git switch -c feature/top-stores
cat > sql/top_stores.sql << 'EOF'
-- Top stores by completed order count
SELECT s.store_id, s.store_name, count(*) AS completed_orders
FROM orders o
JOIN stores s ON o.store_id = s.store_id
WHERE o.status = 'completed'
GROUP BY s.store_id, s.store_name
ORDER BY completed_orders DESC, s.store_id;
EOF
git add sql/top_stores.sql
git commit -m "Add top_stores.sql"
git switch main
git merge feature/top-stores
git branch -d feature/top-stores
git log --oneline
ls sql
4. Optional — bare remote or GitHub
Bare remote (no account)
cd ~/dcubes/git-lab
git init --bare shift-origin.git
cd ~/dcubes/git-lab/shift
git remote add origin ~/dcubes/git-lab/shift-origin.git
git push -u origin main
GitHub (optional)
Create an empty private repo, then:
git remote add origin https://github.com/YOURUSER/retail-shift.git
git push -u origin main
5. Optional — run SQL against sql-lab
export PGPASSWORD=dcubes PGHOST=127.0.0.1 PGPORT=15432 PGUSER=dcubes PGDATABASE=retail
psql -f ~/dcubes/git-lab/shift/sql/revenue_by_category.sql
You passed if
- Two or more commits on
mainwith clear messages -
.envanddata/raw/are ignored -
sql/top_stores.sqlexists onmainafter merge -
git statusis clean
Common mistakes
- Committing
.env— remove from history carefully; rotate any real secret - Merging without switching to
mainfirst - One giant commit with scaffold + feature — split when you can
Next
Foundations spine is complete: Linux → Docker → Python → SQL → Git.
Next on the roadmap: Apache Airflow — the first Data Engineering module. Still guidance only, still on your machine: Airflow Getting Started.