189 lines
3.6 KiB
Markdown
189 lines
3.6 KiB
Markdown
# Git Setup & Workflow
|
|
|
|
## Initiales Repository erstellen
|
|
|
|
```bash
|
|
# 1. Git Repository initialisieren
|
|
git init
|
|
|
|
# 2. Alle Dateien hinzufügen
|
|
git add .
|
|
|
|
# 3. Ersten Commit erstellen
|
|
git commit -m "Initial commit: PHP zu Node.js Migration"
|
|
|
|
# 4. Main Branch umbenennen (optional, wenn du 'main' statt 'master' willst)
|
|
git branch -M main
|
|
```
|
|
|
|
## Remote Repository verbinden
|
|
|
|
### GitHub
|
|
```bash
|
|
# Repository auf GitHub erstellen, dann:
|
|
git remote add origin https://github.com/DEIN_USERNAME/recipe-app.git
|
|
git push -u origin main
|
|
```
|
|
|
|
### GitLab
|
|
```bash
|
|
git remote add origin https://gitlab.com/DEIN_USERNAME/recipe-app.git
|
|
git push -u origin main
|
|
```
|
|
|
|
### Eigener Git-Server
|
|
```bash
|
|
git remote add origin git@dein-server.de:/pfad/zu/recipe-app.git
|
|
git push -u origin main
|
|
```
|
|
|
|
## Empfohlene Branch-Strategie
|
|
|
|
```bash
|
|
# Feature-Branch erstellen
|
|
git checkout -b feature/neue-funktion
|
|
|
|
# Änderungen committen
|
|
git add .
|
|
git commit -m "feat: Neue Funktion hinzugefügt"
|
|
|
|
# In main mergen
|
|
git checkout main
|
|
git merge feature/neue-funktion
|
|
|
|
# Feature-Branch löschen
|
|
git branch -d feature/neue-funktion
|
|
```
|
|
|
|
## Commit-Konventionen
|
|
|
|
```bash
|
|
# Feature
|
|
git commit -m "feat: Neue Suchfunktion für Kategorien"
|
|
|
|
# Bugfix
|
|
git commit -m "fix: Bild-Upload bei langen Dateinamen"
|
|
|
|
# Dokumentation
|
|
git commit -m "docs: README aktualisiert"
|
|
|
|
# Refactoring
|
|
git commit -m "refactor: DB-Verbindung optimiert"
|
|
|
|
# Style
|
|
git commit -m "style: CSS für mobile Ansicht verbessert"
|
|
|
|
# Tests
|
|
git commit -m "test: Unit-Tests für Rezept-API"
|
|
```
|
|
|
|
## Wichtige Dateien NICHT in Git
|
|
|
|
Die `.gitignore` verhindert, dass folgende Dateien committed werden:
|
|
- `node_modules/` - Dependencies (werden via `npm install` installiert)
|
|
- `.env` - Enthält sensible Zugangsdaten
|
|
- `uploads/` - Benutzergenerierte Bilder (zu groß für Git)
|
|
|
|
## Uploads separat sichern
|
|
|
|
Da `uploads/` nicht in Git ist, erstelle ein separates Backup:
|
|
|
|
```bash
|
|
# Backup erstellen
|
|
tar -czf uploads-backup-$(date +%Y%m%d).tar.gz uploads/
|
|
|
|
# Oder mit rsync zu Backup-Server
|
|
rsync -avz uploads/ user@backup-server:/backups/recipe-app/uploads/
|
|
```
|
|
|
|
## .env Template
|
|
|
|
Erstelle eine `.env.example` für andere Entwickler:
|
|
|
|
```bash
|
|
# .env.example (WIRD in Git committed)
|
|
PORT=3000
|
|
NODE_ENV=development
|
|
MONGODB_URI=mongodb://localhost:27017/recipes
|
|
```
|
|
|
|
Dann:
|
|
```bash
|
|
git add .env.example
|
|
git commit -m "docs: .env.example hinzugefügt"
|
|
```
|
|
|
|
Andere Entwickler kopieren dann:
|
|
```bash
|
|
cp .env.example .env
|
|
# Dann .env mit echten Werten anpassen
|
|
```
|
|
|
|
## Git-Befehle Cheatsheet
|
|
|
|
```bash
|
|
# Status anzeigen
|
|
git status
|
|
|
|
# Änderungen anzeigen
|
|
git diff
|
|
|
|
# Log anzeigen
|
|
git log --oneline
|
|
|
|
# Bestimmte Datei rückgängig machen
|
|
git checkout -- datei.js
|
|
|
|
# Letzten Commit rückgängig (behält Änderungen)
|
|
git reset --soft HEAD~1
|
|
|
|
# Alle lokalen Änderungen verwerfen
|
|
git reset --hard HEAD
|
|
|
|
# Remote-Änderungen holen
|
|
git pull
|
|
|
|
# Branch wechseln
|
|
git checkout branch-name
|
|
|
|
# Alle Branches anzeigen
|
|
git branch -a
|
|
```
|
|
|
|
## GitHub Actions (CI/CD) - Optional
|
|
|
|
Erstelle `.github/workflows/deploy.yml` für automatisches Deployment:
|
|
|
|
```yaml
|
|
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- name: Deploy to Server
|
|
run: |
|
|
# SSH in deinen Server und Pull+Restart
|
|
```
|
|
|
|
## Zusammenarbeit mit anderen
|
|
|
|
```bash
|
|
# Anderen Entwickler hinzufügen
|
|
# Auf GitHub: Settings → Collaborators → Add people
|
|
|
|
# Änderungen holen und mergen
|
|
git pull origin main
|
|
|
|
# Bei Merge-Konflikten
|
|
git status # Zeigt konfliktreiche Dateien
|
|
# Dateien manuell bearbeiten und Konflikte lösen
|
|
git add .
|
|
git commit -m "fix: Merge-Konflikte gelöst"
|
|
```
|