From 1a241ff15ea5383215690623e6e1d193035969ba Mon Sep 17 00:00:00 2001 From: rpriven Date: Fri, 17 Jul 2026 23:01:41 -0600 Subject: [PATCH] =?UTF-8?q?add=20git.cheat=20=E2=80=94=20git=20remote/mirr?= =?UTF-8?q?or=20workflow=20reference?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Covers: remote -v/show/add/set-url/rename/remove, push to one or all remotes, mirror-to-self-hosted pattern, and common gotchas. Generic placeholders only (no real infra). Co-Authored-By: Claude Opus 4.8 (1M context) --- git.cheat | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 git.cheat diff --git a/git.cheat b/git.cheat new file mode 100644 index 0000000..4d970ca --- /dev/null +++ b/git.cheat @@ -0,0 +1,59 @@ +% git, remote, remotes, push, mirror, self-hosted, git-remote + +# ============================================================================ +# GIT REMOTES — inspect, add, fix, mirror +# ============================================================================ +# A "remote" = a named URL git pushes/pulls to. `origin` is the default name. +# Common setup: multiple remotes to mirror one repo to several self-hosted git +# boxes for redundancy. HTTPS remotes prompt for a login every push; +# ssh:// remotes authenticate silently with your key — prefer ssh:// for mirrors. + +# List all remotes with their URLs (-v = verbose; shows fetch + push lines) +git remote -v + +# Show details for one remote (tracked branches, HEAD, push URL) +git remote show + +# Add a new remote +git remote add + +# Change an existing remote's URL (e.g. fix HTTPS -> ssh, or a wrong port) +git remote set-url + +# Rename a remote +git remote rename + +# Remove a remote +git remote remove + +# ============================================================================ +# MIRROR TO A SELF-HOSTED GIT SERVER (pattern — swap in your own host/port/owner) +# ============================================================================ +# Self-hosted git over ssh (a custom ssh port is common on such boxes) +git remote set-url origin ssh://git@git.example.com:2222//.git + +# A second self-hosted box as a mirror, on its own port +git remote add mirror ssh://git@gitbox.local://.git + +# Forgot which ssh port a box uses? Survey repos that already point at it: +grep -rhoE "ssh://git@:[0-9]+" ~/github/*/.git/config | sort -u + +# ============================================================================ +# PUSH / MIRROR +# ============================================================================ +# Push current branch to a specific remote +git push + +# Push to ALL configured remotes in one go (loop) +git remote | xargs -I{} git push {} + +# First push of a new branch (sets upstream so later `git push` alone works) +git push -u + +# ============================================================================ +# GOTCHAS +# ============================================================================ +# - HTTPS remote fails non-interactively: "could not read Username" -> switch to ssh:// +# - A repo's remotes live in plain text at .git/config — you can `cat` and read it +# - `git remote -v` shows each remote TWICE (one fetch, one push) — that's normal +