如何从github中提取项目?

时间:2009-09-11 03:08:57

标签: git github

我在github上有一个我以前一直在做的项目。但是,我擦掉了我的电脑,我想知道我应该在我的用户名下调用哪个git命令来再次检查我的项目,以便我可以将我的最新更改推送到我帐户下的github。

6 个答案:

答案 0 :(得分:135)

Git clone是您正在寻找的命令:

git clone git@github.com:username/repo.git

更新: 这是官方指南: https://help.github.com/articles/fork-a-repo

看看: https://help.github.com/

它有非常有用的内容

答案 1 :(得分:33)

首先,你需要告诉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

答案 2 :(得分:10)

运行以下命令:

cd /pathToYourLocalProjectFolder

git pull origin master

答案 3 :(得分:2)

由于您已经清除了计算机并想再次签出项目,因此可以先进行以下初始设置:

git config --global user.name "Your Name"
git config --global user.email youremail@domain.com

登录到github帐户,转到要克隆的存储库,然后在“使用HTTPS克隆”下复制URL。

您可以使用HTTPS克隆远程存储库,即使您上次设置SSH

git clone https://github.com/username/repo-name.git

注意:

如果您以前为远程存储库设置了SSH,则必须将该密钥添加到PC上的已知hosts 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更容易。

答案 4 :(得分:0)

要执行的步骤很少(对于Windows)

  1. 打开Git Bash并生成ssh密钥 粘贴以下文本,替换为您的GitHub电子邮件地址。

    ssh-keygen -t rsa -b 4096 -C“ your_email@example.com

    这将使用提供的电子邮件作为标签来创建新的ssh密钥。

    生成公共/私有rsa密钥对。

    当系统提示您“输入要保存密钥的文件”时,按Enter键。这个 接受默认文件位置。

    输入要保存密钥的文件(/c/Users/you/.ssh/id_rsa):[按Enter]

    在提示符下,键入一个安全密码。有关更多信息,请参阅“使用SSH 关键密码”。

    输入密码(无密码时为空):[输入密码] 再次输入相同的密码:[再次输入密码]

  2. 将密钥添加到SSH代理

    在Git Bash中键入以下内容(99999仅作为示例),以查看代理已启动并正在运行。 评估$(ssh-agent -s) 代理程序pid 99999

    然后输入此内容。

    ssh-add〜/ .ssh / id_rsa

    然后使用此命令将SSH密钥复制到剪贴板

    剪辑<〜/ .ssh / id_rsa.pub

  3. 将SSH密钥添加到Git帐户

    在GitHib网站中,单击右上角的图像,然后选择设置。在下一页中,单击“ SSH和GPG密钥”选项。这将打开SSH密钥页面。单击新建SSH密钥。在“标题”字段中,为新密钥添加一个描述性标签。将密钥粘贴到“密钥”字段中。

  4. 克隆存储库

    打开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/

答案 5 :(得分:0)

您可以通过两种方式完成

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

仅此而已,远程回购中的所有提交和分支现在在您计算机的本地存储库中可用。

快乐编码,加油-:)

相关问题