Probably 99.9% of Git repositories only have one remote, origin, which is The One True Cloud Sync point for the repo. But, it doesn’t have to be that way.
Remote management operations
git remote -v: display all remotes and their push/fetch URLsgit remote add <name> <url>: add a new origin with the given name and URL- Often done on a repo that’s just had a cloud endpoint created for it —
git remote add origin https://...
- Often done on a repo that’s just had a cloud endpoint created for it —
git remote set-url <name> <new-url>: update a given remote, changing its URL to the specified one. Useful if the repo moves, or if you want to switch between HTTP and SSH connections.
URL types
In this case, “URL” is taken literally — uniform resource locator. Git remotes can be, among other things:
- HTTP(S) connections to a web server
- Typically of the form
https://example.com/project_or_user/repo.git
- Typically of the form
- SSH connections
- Typically of the form
ssh://example.com/project_or_user/repo
- Typically of the form
- File paths to a bare repo elsewhere on your filesystem (or on a network drive, etc)
- Fairly freeform,
/path/to/the/repowhererepois the folder containing the.gitfolder
- Fairly freeform,
Remote synchronization operations
Operations for sending and retrieving changes to a remote server.
Syncing Up
For “syncing up” — that is, sending your local changes to a remote:
git push: copy your local commits to the servergit push <remote> <branchname>: send your commits to a specific remote and branch combinationgit push --force: forcibly overwrite differing content on the remoteLoss of data; sync-down problems Editing History for the implications of using this. Your coworkers will probably be mad at you.
See
git push --force-with-lease: similar to--force, but checks that you are only overwriting your own work, and will reject the push if other people have committed to the remote branch.Loss of data; sync-down problems Editing History for the implications of using this. Your coworkers may well still be mad at you, even with the lease option.
See
git push <remote> '*:*': push all refs to the remote at once, including branches, tags, and whatnot. Useful if you want to push everything you have in one shot and then delete your local copy of the repo.
Syncing Down
For “checking” — that is, seeing what else has been updated on a remote without actually changing your local copy:
git fetch: inspect the remote and see what the newest state of all branches aregit fetch <remote>: fetch on a specific remote (useful for multi-remote setups)git fetch --all: fetch all remotes (again, useful for multi-remote setups)