Managing Remotes
A remote is just a saved nickname for another copy of the repository, usually on a server. Ravi's clone got one automatically. Asha started with git init, so her repository knows about no remotes until she adds one. Either way, a handful of commands manage the list.
The rule
A remote is a nickname for a URL; add, list, rename, re-point or remove it.
git remote -v # list remotes and their URLs
git remote add origin https://github.com/asha-dev/recipe-box.git
git remote set-url origin git@github.com:asha-dev/recipe-box.git # new URL
git remote rename origin github # change the nickname
git remote remove github # forget a remoteKey facts:
originis only a convention. It is the name Git gives the place you cloned from, and the name most people choose when adding their main remote. Nothing about it is special.- A repository can have many remotes. When you contribute to someone else's project, it is common to have
originfor your own copy andupstreamfor the original. - Removing a remote deletes nothing on the server. It only removes the nickname, and the remote-tracking branches, from your local repository.
git remote -vshows two lines per remote, one marked(fetch)and one(push). They are normally the same URL.
Remotes also create remote-tracking branches such as origin/main. These are your repository's memory of where each branch was on the remote the last time you talked to it. They update only when you fetch, pull or push, never on their own.
Inspect one remote in detail with:
git remote show originIt lists the remote's branches and which of your local branches push to and pull from them.