我之前在Github上有一个项目,但是后来我清空了电脑。现在我想知道应该使用哪个git命令以我的用户名作为基础重新检出我的项目,以便我可以在我的账户下推送最新的更改到Github。
你要找的命令是 Git clone:
git clone git@github.com:username/repo.git
更新: 这是官方指南: https://help.github.com/articles/fork-a-repo
看一下这个: https://help.github.com/
它有非常有用的内容。
执行以下命令:
cd /pathToYourLocalProjectFolder
git pull origin master
/pathToYourLocalProjectFolder
不再存在。” - Shahbaz如果您已经清除了计算机并想要重新检查您的项目,您可以通过进行以下初始设置来开始:
git config --global user.name "Your Name"
git config --global user.email youremail@domain.com
登录你的 Github 帐户,进入你要克隆的仓库,并复制“使用 HTTPS 克隆”的 URL。
即使上次设置了 SSH,你也可以使用 HTTPS 克隆远程仓库:
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 仓库,
git init or git init repo-name
git pull https://github.com/user-name/repository.git
现在,你的本地仓库中已经包含了远程仓库中的所有提交和分支。
愉快地编码,加油 -:)
打开Git Bash并生成ssh key
粘贴以下文本,将其中的"your_email@example.com"替换为您的GitHub电子邮件地址。
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
这将创建一个新的ssh key,并使用提供的电子邮件地址作为标签。
Generating public/private rsa key pair.
当提示输入“Enter a file in which to save the key”时,请按回车键。这将接受默认的文件位置。
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
在提示符下,输入一个安全的密码。有关更多信息,请参见“使用SSH密钥口令”。
Enter passphrase (empty for no passphrase): [Type a passphrase] Enter same passphrase again: [Type passphrase again]
将key添加到SSH Agent中
在Git Bash中键入以下内容(99999只是一个示例)以查看代理正在运行。
eval $(ssh-agent -s) Agent pid 99999
然后键入此命令。
ssh-add ~/.ssh/id_rsa
然后使用以下命令将SSH key复制到剪贴板。
clip < ~/.ssh/id_rsa.pub
将SSH Key添加到Git账户中
在GitHub网站上,单击右上角的图像,然后选择“Settings”。在随后的页面中,单击SSH和GPG keys选项。这将打开SSH key页面。单击“New SSH key”。在“Title”字段中,为新密钥添加一个描述性标签。将您的key粘贴到“Key”字段中。
克隆存储库
打开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
/path/repo.git
这样的东西,但当我克隆本地repo时,我需要做/path/repo/.git
。我做错了什么吗? - CatShoes