|
|
|
@ -0,0 +1,259 @@ |
|
|
|
|
--- |
|
|
|
|
id: git-workflow-vscode |
|
|
|
|
title: Git & Pull-Request Workflow |
|
|
|
|
sidebar_label: Git & Pull Requests |
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
# 📌 Git & Pull-Request Workflow |
|
|
|
|
|
|
|
|
|
Git ist ein verteiltes Versionskontrollsystem, das häufig in der Softwareentwicklung verwendet wird. Diese Anleitung erklärt die grundlegende Nutzung von Git, den Workflow mit Pull Requests sowie die Integration mit Visual Studio Code. |
|
|
|
|
|
|
|
|
|
## 📝 Voraussetzungen |
|
|
|
|
|
|
|
|
|
- Installiertes Git ([Download hier](https://git-scm.com/)) |
|
|
|
|
- GitHub-, GitLab- oder Bitbucket-Konto (für Remote-Repositories) |
|
|
|
|
- Grundlegende Terminal- oder CLI-Kenntnisse |
|
|
|
|
- **Optional:** [Visual Studio Code](https://code.visualstudio.com/) für eine einfache Nutzung mit Git |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 🔧 Schritt 1: Git auf Windows, Linux & macOS installieren |
|
|
|
|
|
|
|
|
|
### 1️⃣ Git auf Windows installieren |
|
|
|
|
|
|
|
|
|
1. Lade Git von [git-scm.com](https://git-scm.com/) herunter. |
|
|
|
|
2. Führe das Installationsprogramm aus und folge den Anweisungen. |
|
|
|
|
3. Wähle als Standardterminal „Git Bash“ oder „Command Prompt“. |
|
|
|
|
4. Nach der Installation kannst du prüfen, ob Git installiert ist: |
|
|
|
|
```sh |
|
|
|
|
git --version |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### 2️⃣ Git auf Linux (Debian/Ubuntu) |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
sudo apt update && sudo apt install -y git |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### 3️⃣ Git auf macOS |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
brew install git |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 🔧 Schritt 2: Git konfigurieren |
|
|
|
|
|
|
|
|
|
Nach der Installation musst du Git mit deinem Namen und deiner E-Mail-Adresse konfigurieren: |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
git config --global user.name "Dein Name" |
|
|
|
|
git config --global user.email "deine.email@example.com" |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
Überprüfe deine Git-Konfiguration: |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
git config --list |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 📂 Schritt 3: Repository erstellen & klonen |
|
|
|
|
|
|
|
|
|
### 1️⃣ Neues Repository erstellen |
|
|
|
|
|
|
|
|
|
Auf GitHub, GitLab oder Bitbucket: |
|
|
|
|
- Erstelle ein neues Repository mit einem Namen und einer README-Datei. |
|
|
|
|
|
|
|
|
|
### 2️⃣ Repository klonen |
|
|
|
|
|
|
|
|
|
Um das Repository lokal zu klonen: |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
git clone https://github.com/USERNAME/REPOSITORY.git |
|
|
|
|
cd REPOSITORY |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 🔨 Schritt 4: Änderungen vornehmen & committen |
|
|
|
|
|
|
|
|
|
1. **Neue Datei erstellen oder bestehende Datei ändern:** |
|
|
|
|
```sh |
|
|
|
|
echo "Hello World" > hello.txt |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
2. **Status der Änderungen prüfen:** |
|
|
|
|
```sh |
|
|
|
|
git status |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
3. **Änderungen zum Staging-Bereich hinzufügen:** |
|
|
|
|
```sh |
|
|
|
|
git add hello.txt |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
4. **Änderungen committen:** |
|
|
|
|
```sh |
|
|
|
|
git commit -m "Meine erste Datei hinzugefügt" |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 🔄 Schritt 5: Änderungen auf den Remote-Server pushen |
|
|
|
|
|
|
|
|
|
Um die Änderungen auf GitHub/GitLab zu übertragen: |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
git push origin main |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
Falls du auf einem neuen Branch arbeitest: |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
git push origin feature-branch |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 🌿 Schritt 6: Branches & Feature-Branches erstellen |
|
|
|
|
|
|
|
|
|
### 1️⃣ Neuen Branch erstellen: |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
git checkout -b feature-neues-feature |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### 2️⃣ Änderungen vornehmen und committen: |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
git add . |
|
|
|
|
git commit -m "Neues Feature hinzugefügt" |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### 3️⃣ Branch auf Remote-Server pushen: |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
git push origin feature-neues-feature |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 🔄 Schritt 7: Pull Request (PR) erstellen |
|
|
|
|
|
|
|
|
|
1. **Navigiere zu deinem Repository auf GitHub/GitLab.** |
|
|
|
|
2. **Wechsle auf den neuen Branch und klicke auf „Pull Request erstellen“.** |
|
|
|
|
3. **Beschreibe die Änderungen und reiche den PR ein.** |
|
|
|
|
4. **Warte auf eine Code-Review und gegebenenfalls Anpassungen.** |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 🔄 Schritt 8: Pull Request mergen |
|
|
|
|
|
|
|
|
|
Sobald dein PR genehmigt wurde: |
|
|
|
|
- Klicke auf **Merge Pull Request**. |
|
|
|
|
- Lösche optional den Branch: |
|
|
|
|
```sh |
|
|
|
|
git branch -d feature-neues-feature |
|
|
|
|
git push origin --delete feature-neues-feature |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 🔄 Schritt 9: Repository aktuell halten |
|
|
|
|
|
|
|
|
|
Falls sich der `main`-Branch geändert hat, aktualisiere dein lokales Repository: |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
git checkout main |
|
|
|
|
git pull origin main |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
Falls du auf einem Branch arbeitest, kannst du ihn mit `main` synchronisieren: |
|
|
|
|
|
|
|
|
|
```sh |
|
|
|
|
git checkout feature-neues-feature |
|
|
|
|
git merge main |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
Falls Konflikte auftreten, bearbeite sie und committe erneut. |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 💻 Git in Visual Studio Code nutzen |
|
|
|
|
|
|
|
|
|
1. **Visual Studio Code installieren:** |
|
|
|
|
Lade es von [hier](https://code.visualstudio.com/) herunter und installiere es. |
|
|
|
|
|
|
|
|
|
2. **Git in VS Code aktivieren:** |
|
|
|
|
- Öffne VS Code. |
|
|
|
|
- Drücke `Strg + P` (Windows/Linux) oder `Cmd + P` (macOS) und tippe `Git: Enable`. |
|
|
|
|
- Falls Git nicht erkannt wird, setze den Git-Pfad in den Einstellungen. |
|
|
|
|
|
|
|
|
|
3. **Repository klonen:** |
|
|
|
|
- Öffne das `Terminal` in VS Code (``Strg + ` ``). |
|
|
|
|
- Führe den Befehl aus: |
|
|
|
|
```sh |
|
|
|
|
git clone https://github.com/USERNAME/REPOSITORY.git |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
4. **Änderungen vornehmen & committen:** |
|
|
|
|
- Änderungen an Dateien in VS Code speichern. |
|
|
|
|
- In der Seitenleiste `Source Control` (`Strg + Shift + G`) die Änderungen sehen. |
|
|
|
|
- Datei mit `+` zum Staging hinzufügen. |
|
|
|
|
- Commit-Nachricht eingeben und auf `Commit` klicken. |
|
|
|
|
|
|
|
|
|
5. **Änderungen pushen:** |
|
|
|
|
- Im `Source Control` Tab auf `Synchronisieren` klicken oder im Terminal: |
|
|
|
|
```sh |
|
|
|
|
git push origin main |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
6. **Branching & Pull Requests:** |
|
|
|
|
- Klicke unten links auf den aktuellen Branch (`main`). |
|
|
|
|
- Wähle `Neuen Branch erstellen`. |
|
|
|
|
- Nach Änderungen den neuen Branch pushen. |
|
|
|
|
- Auf GitHub/GitLab den PR erstellen und nach Review mergen. |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## 🛑 Schritt 10: Fehlerbehebung (Troubleshooting) |
|
|
|
|
|
|
|
|
|
Falls Git nicht funktioniert, prüfe: |
|
|
|
|
|
|
|
|
|
1. **Ist Git installiert?** |
|
|
|
|
```sh |
|
|
|
|
git --version |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
2. **Wurde Git im Pfad erkannt? (Windows)** |
|
|
|
|
```sh |
|
|
|
|
where git |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
3. **Ist das Repository korrekt initialisiert?** |
|
|
|
|
```sh |
|
|
|
|
git status |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
4. **Hast du die richtigen Zugangsdaten für GitHub/GitLab?** |
|
|
|
|
Falls `fatal: Authentication failed` erscheint, überprüfe deine SSH-Keys oder persönliche Zugriffstokens. |
|
|
|
|
|
|
|
|
|
5. **Konflikte beim Merge?** |
|
|
|
|
Falls `CONFLICT (content)` erscheint, öffne die betroffenen Dateien in VS Code und löse die Konflikte. |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## ✅ Fazit |
|
|
|
|
|
|
|
|
|
Nun bist du bereit, mit Git zu arbeiten, Pull Requests effizient zu nutzen und Git in Visual Studio Code zu integrieren. |
|
|
|
|
|
|
|
|
|
Falls du Fragen hast, sieh dir die offiziellen Dokumentationen an: |
|
|
|
|
|
|
|
|
|
- [GitHub Docs](https://docs.github.com/en) |
|
|
|
|
- [GitLab Docs](https://docs.gitlab.com/) |
|
|
|
|
- [Atlassian Git-Tutorials](https://www.atlassian.com/git/tutorials) |
|
|
|
|
|
|
|
|
|
Happy Coding! 🚀 |