add git.cheat — git remote/mirror workflow reference
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) <noreply@anthropic.com>
This commit is contained in:
parent
4ff6f7be6c
commit
1a241ff15e
1 changed files with 59 additions and 0 deletions
59
git.cheat
Normal file
59
git.cheat
Normal file
|
|
@ -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 <remote_name>
|
||||||
|
|
||||||
|
# Add a new remote
|
||||||
|
git remote add <remote_name> <url>
|
||||||
|
|
||||||
|
# Change an existing remote's URL (e.g. fix HTTPS -> ssh, or a wrong port)
|
||||||
|
git remote set-url <remote_name> <url>
|
||||||
|
|
||||||
|
# Rename a remote
|
||||||
|
git remote rename <old_name> <new_name>
|
||||||
|
|
||||||
|
# Remove a remote
|
||||||
|
git remote remove <remote_name>
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 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/<owner>/<repo>.git
|
||||||
|
|
||||||
|
# A second self-hosted box as a mirror, on its own port
|
||||||
|
git remote add mirror ssh://git@gitbox.local:<ssh_port>/<owner>/<repo>.git
|
||||||
|
|
||||||
|
# Forgot which ssh port a box uses? Survey repos that already point at it:
|
||||||
|
grep -rhoE "ssh://git@<host>:[0-9]+" ~/github/*/.git/config | sort -u
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# PUSH / MIRROR
|
||||||
|
# ============================================================================
|
||||||
|
# Push current branch to a specific remote
|
||||||
|
git push <remote_name>
|
||||||
|
|
||||||
|
# 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 <remote_name> <branch>
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 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
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue