Git - Managing Remotes Flashcards
Changing a remotes URL
git remote set-url
Changes an existing remote repository URL.
The git remote set-url command takes two arguments:
- An existing remote name origin or upstream
- A new URL for the remote:
HTTPS: https://github.com/USERNAME/REPOSITORY.git
SSH: git@github.com:USERNAME/REPOSITORY.git
Switch remote URL from SSH to HTTPS
List existing remotes in order to get the name of the remote you want to change.
git remote -v
Change remotes URL from SSH to HTTPS with git remote set-url:
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
Verify that the remote URL has changed
git remote -v
Switch remote URLs from HTTPS to SSH
List existing remotes to get the name of remote you want to change
git remote -v
Change remotes URL from HTTPS to SSH with git remote set-url
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
Verify remote url has changed
git remote -v
What is a remote repository
Remote repositories are versions of your project that are hosted on the internet or network somewhere.
You can have several of them each of which is generally read-only or read/write.
Collaborating with others requires managing these remotes and pushing and pulling data from them when you need to share work.
Managing remotes involves: adding remotes, removing remotes, manage various remote branches, and define them as being tracked or not.
To see which remote servers you have configured.
git remote
Lists the short names of each remote handle you’ve specified.
If you’ve cloned your repository you should at least see origin which is the default name Git gives to the server you cloned from.
Show URL git has stored for the short name.
git remote -v
When reading and writing to that remote.
If you have more than one remote the command line lists them all e.g. a repository with multiple remotes for working with several collaborators. (This means you can pull contributions from any of those users) you may additionally have permissions to push to one or more of these.
Adding remote repositories
Git clone command implicitly adds the remote origin for you.
To add a new remote git repository as a shortname you can reference easily run:
git remote add
Pull down data from a remote project that you don’t have using
git fetch
git fetch
This command goes out to the remote project and pulls down all the data from the remote project that you do not have which you can merge in or inspect at any time.
Git fetch only downloads the data to your local repository — it doesn’t automatically merge it with any of your work or modify what you’re currently working on. You have to merge it manually into your work when your ready.