git-remote-branch.md
- hinzugefügt - tools/collector/link_collector.py nach POSIX refaktoriert
This commit is contained in:
parent
e7af04c84d
commit
42afb2769a
@ -1,5 +1,7 @@
|
||||
# Admin´s Log
|
||||
|
||||
Kleine Sammlung von Gedächnissstützen für den privaten und persönlichen Gebrauch.
|
||||
|
||||
## Inhalt
|
||||
|
||||
- [Admin´s Log](#admins-log)
|
||||
@ -33,7 +35,8 @@
|
||||
### Git
|
||||
|
||||
- [Artikel: git](dokus/git/git.md)
|
||||
- [SSH-Zugriff auf Git-Repository in WSL einrichten](dokus/git/git-ssh-remote.md)
|
||||
- [SSH-Zugriff auf Git-Repository in WSL einrichten](dokus/git/git-ssh-remote.md)
|
||||
- [Git – Remote-Branches: Häufige Aufgaben und Lösungen](dokus/git/git-remote-branch.md)
|
||||
|
||||
### Markdown
|
||||
|
||||
@ -52,3 +55,5 @@
|
||||
## Neue Dokumente
|
||||
|
||||
> führe `scan.cmd` oder [`link_collector.py`](./tools/collector/link_collector.py) aus um nach neuen Dateien zu suchen!
|
||||
|
||||
**NEUE EINTRÄGE AUS './tools/collector/link_collector.py'->**
|
||||
|
162
dokus/git/git-remote-branch.md
Normal file
162
dokus/git/git-remote-branch.md
Normal file
@ -0,0 +1,162 @@
|
||||
# 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` |
|
@ -1 +1,4 @@
|
||||
# Artikel: git
|
||||
|
||||
- [SSH-Zugriff auf Git-Repository in WSL einrichten](git-ssh-remote.md)
|
||||
- [Git – Remote-Branches: Häufige Aufgaben und Lösungen](git-remote-branch.md)
|
||||
|
@ -2,29 +2,33 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
# Gibt das Verzeichnis zurück, in dem dieses Skript liegt
|
||||
def script_dir():
|
||||
return Path(__file__).parent.resolve()
|
||||
|
||||
# Lädt die JSONC-Konfiguration (Kommentare via // werden ignoriert)
|
||||
def load_config(filename="config.jsonc"):
|
||||
config_path = script_dir() / filename
|
||||
if not config_path.exists():
|
||||
print(" ⚠ Konfigurationsdatei nicht gefunden:", config_path)
|
||||
sys.exit(1)
|
||||
with open(config_path, encoding="utf-8") as f:
|
||||
# Entfernt //-Kommentare vor dem Parsen
|
||||
return json.loads("".join(line for line in f if not line.strip().startswith("//")))
|
||||
|
||||
# Parsen der Kommandozeilenargumente
|
||||
def parse_args():
|
||||
args = sys.argv[1:]
|
||||
parsed = {
|
||||
"scan": None,
|
||||
"ignore": [],
|
||||
"reset": False,
|
||||
"hilfe": False,
|
||||
"scan": None, # Verzeichnisse zum Scannen (List[str])
|
||||
"ignore": [], # Verzeichnisse, die ignoriert werden sollen (List[str])
|
||||
"reset": False, # Setzt das Logfile zurück
|
||||
"hilfe": False, # Zeigt die Hilfe an
|
||||
}
|
||||
|
||||
# Argumente durchgehen und zuweisen
|
||||
while args:
|
||||
arg = args.pop(0)
|
||||
if arg in ("-h", "--hilfe"):
|
||||
@ -42,11 +46,12 @@ def parse_args():
|
||||
|
||||
return parsed
|
||||
|
||||
# Ausgabe der Hilfetexte für CLI-Nutzer
|
||||
def show_help():
|
||||
print("""
|
||||
(C) 2025 - Adam Skotarczak (ionivation.com)
|
||||
|
||||
🛈 Tool das Verzeichnisse nach Markdown-Dateien duchsucht und diese an eine definierte Liste anhängt als Markdown-Link.
|
||||
🛈 Tool das Verzeichnisse nach Markdown-Dateien durchsucht und diese an eine definierte Liste anhängt als Markdown-Link.
|
||||
Verwendung: python3 link_collector.py [OPTIONEN]
|
||||
|
||||
-s, --scan Kommagetrennte Liste von Verzeichnissen zum Durchsuchen (relativ zum Aufrufpfad)
|
||||
@ -58,15 +63,18 @@ Beispiel:
|
||||
python3 link_collector.py -s docs,notes -x "docs/alt"
|
||||
""")
|
||||
|
||||
# Generator: Findet Markdown-Dateien (rekursiv), ignoriert dabei definierte Pfade
|
||||
def find_md_files(root_dirs, ignore_dirs, extensions):
|
||||
for root in root_dirs:
|
||||
for dirpath, _, filenames in os.walk(root):
|
||||
# Ignorierpfade überspringen
|
||||
if any(str(Path(dirpath)).startswith(str(ignored)) for ignored in ignore_dirs):
|
||||
continue
|
||||
for fname in filenames:
|
||||
if any(fname.endswith(ext) for ext in extensions):
|
||||
yield Path(dirpath) / fname
|
||||
|
||||
# Extrahiert den ersten Markdown-Titel (# ...) als Linktext
|
||||
def extract_title(filepath):
|
||||
try:
|
||||
with open(filepath, encoding="utf-8") as f:
|
||||
@ -75,24 +83,30 @@ def extract_title(filepath):
|
||||
return line.strip("# ").strip()
|
||||
except Exception as e:
|
||||
print(f"⚠ Fehler beim Lesen von {filepath}: {e}")
|
||||
# Fallback: Dateiname ohne Endung
|
||||
return filepath.stem
|
||||
|
||||
# Liest bereits verarbeitete Dateien aus dem Log (Pfadangaben im POSIX-Format)
|
||||
def load_processed(logfile):
|
||||
if not logfile.exists():
|
||||
return set()
|
||||
with open(logfile, encoding="utf-8") as f:
|
||||
return set(line.strip() for line in f)
|
||||
# Vereinheitlichung auf POSIX-Konvention
|
||||
return set(Path(line.strip()).as_posix() for line in f)
|
||||
|
||||
# Hängt neue Markdown-Links ans Output-Dokument an
|
||||
def append_to_output(output_path, links):
|
||||
with open(output_path, "a", encoding="utf-8") as f:
|
||||
for line in links:
|
||||
f.write(line + "\n")
|
||||
|
||||
# Ergänzt das Logfile um neu verarbeitete Dateien (POSIX-Format)
|
||||
def update_processed(log_path, new_paths):
|
||||
with open(log_path, "a", encoding="utf-8") as f:
|
||||
for path in new_paths:
|
||||
f.write(str(path) + "\n")
|
||||
f.write(path.as_posix() + "\n")
|
||||
|
||||
# Hauptfunktion mit gesamtem Ablauf
|
||||
def main():
|
||||
config = load_config()
|
||||
args = parse_args()
|
||||
@ -103,6 +117,7 @@ def main():
|
||||
|
||||
log_path = script_dir() / config.get("processed_log", "processed.log")
|
||||
|
||||
# Optionaler Reset des Logs
|
||||
if args["reset"]:
|
||||
if log_path.exists():
|
||||
log_path.unlink()
|
||||
@ -114,6 +129,7 @@ def main():
|
||||
cwd = Path.cwd()
|
||||
output_file = cwd / config.get("output_file", "output.md")
|
||||
|
||||
# Verzeichnisse aus CLI oder Konfiguration
|
||||
root_dirs = args["scan"] or config.get("root_dirs", [])
|
||||
root_dirs = [Path(d).resolve() for d in root_dirs if d.strip()]
|
||||
ignore_dirs = [Path(x).resolve() for x in args["ignore"]]
|
||||
@ -124,16 +140,19 @@ def main():
|
||||
new_links = []
|
||||
new_processed = []
|
||||
|
||||
# Dateien durchsuchen und neue Markdown-Dateien verlinken
|
||||
for md_file in find_md_files(root_dirs, ignore_dirs, extensions):
|
||||
if md_file.resolve() == output_file.resolve():
|
||||
continue
|
||||
continue # nicht sich selbst verlinken
|
||||
rel_path = md_file.relative_to(cwd)
|
||||
if str(rel_path) in processed:
|
||||
continue
|
||||
rel_path_posix = rel_path.as_posix()
|
||||
if rel_path_posix in processed:
|
||||
continue # bereits im Logfile
|
||||
title = extract_title(md_file)
|
||||
new_links.append(f"- [{title}]({rel_path.as_posix()})")
|
||||
new_links.append(f"- [{title}]({rel_path_posix})")
|
||||
new_processed.append(rel_path)
|
||||
|
||||
# Ergebnisse schreiben
|
||||
if new_links:
|
||||
append_to_output(output_file, new_links)
|
||||
update_processed(log_path, new_processed)
|
||||
|
@ -1,8 +1,5 @@
|
||||
dokus\asciidoc\asciidoctor-theme-bug-workaround.md
|
||||
dokus\git\git-ssh-remote.md
|
||||
dokus\git\git.md
|
||||
dokus\apache-plesk\lets-encrypt-plesk.md
|
||||
dokus/apache-plesk/lets-encrypt-plesk.md
|
||||
dokus/asciidoc/asciidoctor-theme-bug-workaround.md
|
||||
dokus/git/git-remote-branch.md
|
||||
dokus/git/git-ssh-remote.md
|
||||
dokus/git/git.md
|
||||
|
Loading…
x
Reference in New Issue
Block a user