- hinzugefügt - tools/collector/link_collector.py nach POSIX refaktoriert
163 lines
4.1 KiB
Markdown
163 lines
4.1 KiB
Markdown
# Git – Remote-Branches: Häufige Aufgaben und Lösungen
|
||
|
||
**Stand:** 2025-05-26
|
||
|
||
> Diese Anleitung erklärt, wie man mit Remote-Branches arbeitet – insbesondere dann, wenn der Branch lokal noch nicht existiert oder gezielt ressourcenschonend gearbeitet werden soll.
|
||
|
||
---
|
||
|
||
## 📌 Inhalt
|
||
|
||
- [Git – Remote-Branches: Häufige Aufgaben und Lösungen](#git--remote-branches-häufige-aufgaben-und-lösungen)
|
||
- [📌 Inhalt](#-inhalt)
|
||
- [❓ 1. Wie hole ich einen Remote-Branch, den ich lokal noch nicht habe?](#-1-wie-hole-ich-einen-remote-branch-den-ich-lokal-noch-nicht-habe)
|
||
- [❓ 2. Warum sehe ich den Remote-Branch nicht in `git branch -r`?](#-2-warum-sehe-ich-den-remote-branch-nicht-in-git-branch--r)
|
||
- [❓ 3. Holt `git clone` automatisch alle Branches?](#-3-holt-git-clone-automatisch-alle-branches)
|
||
- [❓ 4. Wie klone ich gezielt nur einen bestimmten Branch?](#-4-wie-klone-ich-gezielt-nur-einen-bestimmten-branch)
|
||
- [❓ 5. Wann ist `--single-branch` sinnvoll?](#-5-wann-ist---single-branch-sinnvoll)
|
||
- [❓ 6. Wie sehe ich alle Remote-Branches **vor** dem Clonen?](#-6-wie-sehe-ich-alle-remote-branches-vor-dem-clonen)
|
||
- [🛠️ Optionaler Alias-Tipp](#️-optionaler-alias-tipp)
|
||
- [🧠 Zusammenfassung](#-zusammenfassung)
|
||
|
||
---
|
||
|
||
## ❓ 1. Wie hole ich einen Remote-Branch, den ich lokal noch nicht habe?
|
||
|
||
```bash
|
||
git fetch
|
||
git checkout -b <lokaler-name> origin/<remote-branch>
|
||
```
|
||
|
||
Alternativ automatisch als Tracking-Branch:
|
||
|
||
```bash
|
||
git checkout --track origin/<remote-branch>
|
||
```
|
||
|
||
Beispiel:
|
||
|
||
```bash
|
||
git checkout --track origin/feature/chat-system
|
||
```
|
||
|
||
---
|
||
|
||
## ❓ 2. Warum sehe ich den Remote-Branch nicht in `git branch -r`?
|
||
|
||
`git branch -r` zeigt nur die lokal bekannten Remote-Refs.
|
||
Du musst vorher `git fetch` ausführen:
|
||
|
||
```bash
|
||
git fetch
|
||
git branch -r
|
||
```
|
||
|
||
Optional: erzwungen alles holen:
|
||
|
||
```bash
|
||
git fetch origin '+refs/heads/*:refs/remotes/origin/*'
|
||
```
|
||
|
||
---
|
||
|
||
## ❓ 3. Holt `git clone` automatisch alle Branches?
|
||
|
||
**Nicht ganz.** `git clone`:
|
||
|
||
- ✅ holt alle Branches als Referenzen
|
||
- ❌ checkt nur den Standard-Branch (z. B. `main`) lokal aus
|
||
|
||
**Weitere Branches** müssen manuell ausgecheckt werden:
|
||
|
||
```bash
|
||
git checkout --track origin/<branch-name>
|
||
```
|
||
|
||
Optional zur Sicherheit vorher:
|
||
|
||
```bash
|
||
git fetch
|
||
git branch -r
|
||
```
|
||
|
||
---
|
||
|
||
## ❓ 4. Wie klone ich gezielt nur einen bestimmten Branch?
|
||
|
||
Nur den gewünschten Branch klonen (kein anderer wird geholt):
|
||
|
||
```bash
|
||
git clone --branch <branch-name> --single-branch <repo-url>
|
||
```
|
||
|
||
Mit reduziertem Verlauf (nur letzte Commits):
|
||
|
||
```bash
|
||
git clone --branch <branch-name> --single-branch --depth 1 <repo-url>
|
||
```
|
||
|
||
---
|
||
|
||
## ❓ 5. Wann ist `--single-branch` sinnvoll?
|
||
|
||
Diese Variante ist ideal, wenn:
|
||
|
||
- du **nur an einem Branch arbeiten** willst
|
||
- du **Platz oder Zeit sparen** möchtest
|
||
- du das Repo **später einfach löschen** willst
|
||
- du z. B. in **CI/CD**, **Docker**, **VMs** oder **temporär lokal** arbeitest
|
||
|
||
Sie vermeidet unnötige Daten und beschleunigt den Clone-Prozess.
|
||
|
||
---
|
||
|
||
## ❓ 6. Wie sehe ich alle Remote-Branches **vor** dem Clonen?
|
||
|
||
Du kannst dir **alle Branches am Remote-Repo anzeigen lassen**, ohne zu klonen:
|
||
|
||
```bash
|
||
git ls-remote --heads <repo-url>
|
||
```
|
||
|
||
Beispiel:
|
||
|
||
```bash
|
||
git ls-remote --heads ssh://git@local.ionivation.com:2222/codewalker/codewalker.net.git
|
||
```
|
||
|
||
Ergebnis:
|
||
|
||
```text
|
||
f3a91d... refs/heads/main
|
||
c4bd79... refs/heads/feature/chat-system
|
||
```
|
||
|
||
---
|
||
|
||
## 🛠️ Optionaler Alias-Tipp
|
||
|
||
Wenn du häufig neue Branches holen willst:
|
||
|
||
```bash
|
||
git config --global alias.fr 'fetch && branch -r'
|
||
```
|
||
|
||
Verwendung:
|
||
|
||
```bash
|
||
git fr
|
||
```
|
||
|
||
= `git fetch` + Anzeige aller Remote-Branches
|
||
|
||
---
|
||
|
||
## 🧠 Zusammenfassung
|
||
|
||
| Ziel | Befehl |
|
||
|-------------------------------------|------------------------------------------------------|
|
||
| Remote-Branch holen + auschecken | `git fetch` + `git checkout --track origin/<name>` |
|
||
| Nur einen Branch klonen | `git clone --branch <name> --single-branch <url>` |
|
||
| Branchliste ohne Clone anzeigen | `git ls-remote --heads <repo-url>` |
|
||
| Lokale Sichtbarkeit Remote-Branches | `git fetch` + `git branch -r` |
|