【发布时间】:2010-11-27 09:13:57
【问题描述】:
我在 github 上有一个我之前一直在研究的项目。但是,我清除了我的计算机,我想知道我应该在我的用户名下调用哪个 git 命令来再次签出我的项目,以便我可以将我的最新更改推送到我的帐户下的 github。
【问题讨论】:
我在 github 上有一个我之前一直在研究的项目。但是,我清除了我的计算机,我想知道我应该在我的用户名下调用哪个 git 命令来再次签出我的项目,以便我可以将我的最新更改推送到我的帐户下的 github。
【问题讨论】:
Git clone 是您要查找的命令:
git clone git@github.com:username/repo.git
更新: 这是官方指南: https://help.github.com/articles/fork-a-repo
内容很实用
【讨论】:
/path/repo.git 这样的东西,但是当我克隆本地仓库时我需要做/path/repo/.git 我做错了什么吗?
首先,您需要向 git 介绍您自己。从您的settings page 获取您的用户名和令牌。
然后运行:
git config --global github.user YOUR_USERNAME
git config --global github.token YOURTOKEN
如果您没有密钥备份,则需要generate a new key。
那么你应该可以运行了:
git clone git@github.com:YOUR_USERNAME/YOUR_PROJECT.git
【讨论】:
运行这些命令:
cd /pathToYourLocalProjectFolder
git pull origin master
【讨论】:
/pathToYourLocalProjectFolder 不存在了。
需要遵循几个步骤(适用于 Windows)
打开 Git Bash 并生成 ssh 密钥 粘贴下面的文本,替换为您的 GitHub 电子邮件地址。
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
这会创建一个新的 ssh 密钥,使用提供的电子邮件作为标签。
生成公钥/私钥 rsa 密钥对。
当系统提示您“输入保存密钥的文件”时,按 Enter。这 接受默认文件位置。
输入要保存密钥的文件(/c/Users/you/.ssh/id_rsa):[按回车键]
在提示符处,键入安全密码。有关详细信息,请参阅“使用 SSH 密钥密码”。
Enter passphrase (empty for no passphrase): [Type a passphrase] 再次输入相同的密码:[再次输入密码]
将密钥添加到 SSH 代理
在 Git Bash 中键入以下内容(99999 只是一个示例)以查看代理是否已启动并正在运行。 评估 $(ssh-agent -s) 代理 pid 99999
然后输入这个。
ssh-add ~/.ssh/id_rsa
然后使用此命令将 SSH 密钥复制到剪贴板
剪辑
将 SSH 密钥添加到 Git 帐户
在 GitHib 站点中,点击右上角的图片,然后选择设置。在随后的页面中,单击 SSH 和 GPG 密钥选项。这将打开 SSH 密钥页面。单击新建 SSH 密钥。在“标题”字段中,为新键添加描述性标签。将您的密钥粘贴到“密钥”字段中。
克隆存储库
打开 VS Code(或任何具有命令提示符等的 IDE/CLI)。使用 cd 命令转到要克隆的目录,然后键入以下行。 git config --global github.user yourGitUserName git config --global user.email your_email git clone git@github.com:yourGitUserName/YourRepoName.git
https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
【讨论】:
由于您已经清除了计算机并想再次签出您的项目,您可以从以下初始设置开始:
git config --global user.name "Your Name"
git config --global user.email youremail@domain.com
登录你的github账号,进入你要克隆的仓库,复制“Clone with HTTPS”下的URL。
您可以使用 HTTPS 克隆远程存储库,即使您上次设置了 SSH:
git clone https://github.com/username/repo-name.git
注意:
如果您之前为远程存储库设置了 SSH,则必须将该密钥添加到 PC 上已知的主机 ssh 文件中;如果您不这样做并尝试执行git clone git@github.com:username/repo-name.git,您将看到类似于以下错误:
Cloning into 'repo-name'...
The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXDoJWGl7E1IGOCspZomTxdCARLviMw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
在这种情况下,使用 HTTPS 比 SSH 更容易。
【讨论】:
你可以通过两种方式来做,
1.将远程仓库克隆到本地主机
示例:git clone https://github.com/user-name/repository.git
2。将远程仓库拉到本地主机
首先你必须创建一个 git local repo,
示例: git init 或 git init 存储库名称 然后,git pull https://github.com/user-name/repository.git
就是这样,远程存储库中的所有提交和分支现在都可以在您计算机的本地存储库中使用。
编码愉快,干杯 -:)
【讨论】: