Git Remote
A Git remote is a named link to another copy of your repository, usually hosted on GitHub, GitLab or Bitbucket. Remotes let you back up your work and share it with others. The default remote name is origin.
Cloning a Repository
git clone downloads a full copy of a repository, including all history, and sets up origin for you.
git clone https://github.com/vitejs/vite.git
cd vite
git remote -vCloning into 'vite'... remote: Enumerating objects: 98213, done. Receiving objects: 100% (98213/98213), 41.20 MiB | 9.8 MiB/s, done. origin https://github.com/vitejs/vite.git (fetch) origin https://github.com/vitejs/vite.git (push)
Connecting an Existing Project
-u sets the upstream, so later you can simply type git push and git pull.
git remote add origin https://github.com/you/portfolio.git
git branch -M main
git push -u origin mainEnumerating objects: 15, done. To https://github.com/you/portfolio.git * [new branch] main -> main branch 'main' set up to track 'origin/main'.
HTTPS vs SSH
With HTTPS, Git asks for credentials; GitHub requires a personal access token or a credential manager instead of your password. SSH uses a key pair, so once set up you never type credentials.
ssh-keygen -t ed25519 -C "you@example.com"
# copy the public key and add it in GitHub > Settings > SSH keys
cat ~/.ssh/id_ed25519.pub
ssh -T git@github.com
git remote set-url origin git@github.com:you/portfolio.gitHi you! You've successfully authenticated, but GitHub does not provide shell access.
Managing Remotes
git remote -v # list remotes
git remote rename origin github # rename
git remote remove old-server # remove
git remote add upstream https://github.com/original/project.gitgithub git@github.com:you/portfolio.git (fetch) github git@github.com:you/portfolio.git (push) upstream https://github.com/original/project.git (fetch) upstream https://github.com/original/project.git (push)
Remote-Tracking Branches
Git keeps read-only copies of remote branches, named like origin/main. They show where the remote was the last time you talked to it. git branch -r lists them, and git switch feature/x automatically creates a local branch tracking origin/feature/x if it exists.
Frequently asked questions
What does origin mean in Git?
origin is the default name Git gives the remote you cloned from. It is just a nickname for the remote URL and can be renamed.
How do I change the remote URL in Git?
Run git remote set-url origin <new-url>, for example when switching from HTTPS to SSH or moving the repository.
Should I use HTTPS or SSH for GitHub?
Both are secure. SSH is convenient once your key is set up; HTTPS with a credential manager works well behind strict firewalls.