About remote repositories
A remote URL is Git's fancy way of saying "the place where your code is stored." That URL could be your repository on GitHub, or another user's fork, or even on a completely different server.
You can only push to two types of URL addresses:
- An HTTPS URL like
https://github.com/user/repo.git
- An SSH URL, like
git@github.com:user/repo.git
Git associates a remote URL with a name, and your default remote is usually called origin
.
Creating remote repositories
You can use the git remote add
command to match a remote URL with a name.
For example, you'd type the following in the command line:
git remote add origin <REMOTE_URL>
This associates the name origin
with the REMOTE_URL
.
You can use the command git remote set-url
to change a remote's URL.
Choosing a URL for your remote repository
There are several ways to clone repositories available on GitHub.
When you view a repository while signed in to your account, the URLs you can use to clone the project onto your computer are available below the repository details.
For information on setting or changing your remote URL, see Managing remote repositories.
Cloning with HTTPS URLs
The https://
clone URLs are available on all repositories, regardless of visibility. https://
clone URLs work even if you are behind a firewall or proxy.
When you git clone
, git fetch
, git pull
, or git push
to a private remote repository using HTTPS URLs on the command line, Git will ask for your GitHub username and password. 当 Git 提示你输入密码时,请输入你的personal access token。 或者,可以使用 Git 凭据管理器等凭据帮助程序。 Git 的基于密码的身份验证已被删除,取而代之的是更安全的身份验证方法。 有关详细信息,请参阅“管理个人访问令牌”。
如果要访问使用 SAML SSO 的组织,并且使用的是 personal access token (classic),则在进行身份验证之前,还必须授权 personal access token 访问该组织。 有关详细信息,请参阅“关于使用 SAML 单点登录进行身份验证”和“授权用于 SAML 单点登录的个人访问令牌”。
Tip
- You can use a credential helper so Git will remember your GitHub credentials every time it talks to GitHub. For more information, see Caching your GitHub credentials in Git.
- To clone a repository without authenticating to GitHub on the command line, you can use GitHub Desktop to clone instead. For more information, see 将仓库从 GitHub 克隆到 GitHub Desktop.
If you'd rather use SSH but cannot connect over port 22, you might be able to use SSH over the HTTPS port. For more information, see 在 HTTPS 端口使用 SSH.
Cloning with SSH URLs
SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and add the public key to your account on GitHub. For more information, see 通过 SSH 连接到 GitHub.
When you git clone
, git fetch
, git pull
, or git push
to a remote repository using SSH URLs, you'll be prompted for a password and must provide your SSH key passphrase. For more information, see 使用 SSH 密钥密码.
If you are accessing an organization that uses SAML single sign-on (SSO), you must authorize your SSH key to access the organization before you authenticate. For more information, see 关于使用 SAML 单点登录进行身份验证 and 授权用于 SAML 单点登录的 SSH 密钥.
Tip
You can use an SSH URL to clone a repository to your computer, or as a secure way of deploying your code to production servers. You can also use SSH agent forwarding with your deploy script to avoid managing keys on the server. For more information, see 使用 SSH 代理转发.
Cloning with GitHub CLI
You can also install GitHub CLI to use GitHub workflows in your terminal. For more information, see 关于 GitHub CLI.