Git Reference / Remotes & collaboration
08Remotes & collaboration
Manage remotes
Named URLs for other copies of the repo.
git remote -v git remote add origin git@github.com:me/repo.git git remote add upstream git@github.com:org/repo.git git remote set-url origin <new-url> git remote prune origin
Fetch vs pull
fetch downloads; pull = fetch + merge (or rebase).
git fetch --all --prune git pull # fetch + integrate git pull --rebase git pull --ff-only # refuse if not fast-forward
Push
Publish your commits.
git push -u origin feature # set upstream git push git push --force-with-lease # safe force push git push --tags
Keep a fork in sync
Pull upstream changes into your fork.
git fetch upstream git switch main git rebase upstream/main git push --force-with-lease
Prefer
--force-with-lease over --forceIt refuses to overwrite the remote if someone else pushed since your last fetch.