git 如何从 github 中提取我的项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1408790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:02:01  来源:igfitidea点击:

How do I pull my project from github?

gitgithub

提问by Thierry Lam

I have a project on github that I have been working on before. However, I wiped out my computer and I am wondering which git command should I invoke under my username to checkout my project again so that I can push my latest changes to github under my account.

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

回答by Santi

Git clone is the command you're looking for:

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

git clone [email protected]:username/repo.git

Update: And this is the official guide: https://help.github.com/articles/fork-a-repo

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

Take a look at: https://help.github.com/

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

It has really useful content

它有非常有用的内容

回答by seth

First, you'll need to tell git about yourself. Get your username and token together from your settings page.

首先,你需要告诉 git 关于你自己。从您的设置页面获取您的用户名和令牌。

Then run:

然后运行:

git config --global github.user YOUR_USERNAME
git config --global github.token YOURTOKEN

You will need to generate a new keyif you don't have a back-up of your key.

如果您没有密钥的备份,您将需要生成一个新密钥。

Then you should be able to run:

然后你应该能够运行:

git clone [email protected]:YOUR_USERNAME/YOUR_PROJECT.git

回答by Udayantha Udy Warnasuriya

Run these commands:

运行这些命令:

cd /pathToYourLocalProjectFolder

git pull origin master

回答by Udayantha Udy Warnasuriya

Since you have wiped out your computer and want to checkout your project again, you could start by doing the below initial settings:

由于您已经清除了您的计算机并想再次签出您的项目,您可以从执行以下初始设置开始:

git config --global user.name "Your Name"
git config --global user.email [email protected]

Login to your github account, go to the repository you want to clone, and copy the URL under "Clone with HTTPS".

登录你的github账号,进入你要克隆的仓库,复制“Clone with HTTPS”下的URL。

You can clone the remote repository by using HTTPS, even if you had setup SSH the last time:

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

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

NOTE:

笔记:

If you had setup SSH for your remote repository previously, you will have to add that key to the known hosts ssh file on your PC; if you don't and try to do git clone [email protected]:username/repo-name.git, you will see an error similar to the one below:

如果您之前为远程存储库设置了 SSH,则必须将该密钥添加到 PC 上的已知主机 ssh 文件中;如果你不这样做并尝试去做git clone [email protected]: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.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Using HTTPS is a easier than SSH in this case.

在这种情况下,使用 HTTPS 比 SSH 更容易。

回答by Vintage Coder

You Can do by Two ways,

你可以通过两种方式做到,

1. Cloning the Remote Repo to your Local host

1. 将远程仓库克隆到本地主机

example: git clone https://github.com/user-name/repository.git

示例:git clone https://github.com/user-name/repository.git

2. Pulling the Remote Repo to your Local host

2. 拉取远程仓库到你的本地主机

First you have to create a git local repo by,

首先,您必须通过以下方式创建一个 git 本地存储库,

example: git init or git init repo-namethen, git pull https://github.com/user-name/repository.git

例如: git init 或 git init repo-name然后,git pull https://github.com/user-name/repository.git

That's all, All commits and branch in the remote repo now available in the local repository of your computer.

就是这样,远程存储库中的所有提交和分支现在可以在您计算机的本地存储库中使用。

Happy Coding, cheers -:)

快乐编码,干杯 - :)

回答by Prem

There are few steps to be followed (For Windows)

需要遵循几个步骤(对于 Windows)

  1. Open Git Bash and generate ssh keyPaste the text below, substituting in your GitHub email address.

    ssh-keygen -t rsa -b 4096 -C "[email protected]"

    This creates a new ssh key, using the provided email as a label.

    Generating public/private rsa key pair.

    When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.

    Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]

    At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases".

    Enter passphrase (empty for no passphrase): [Type a passphrase] Enter same passphrase again: [Type passphrase again]

  2. Add the key to SSH Agent

    Type the following in Git Bash (99999 is just an example) to see agent is up and running. eval $(ssh-agent -s) Agent pid 99999

    then type this.

    ssh-add ~/.ssh/id_rsa

    then Copy the SSH key to your clipboard using this command

    clip < ~/.ssh/id_rsa.pub

  3. Add the SSH Key to the Git Account

    In GitHib site, click on the image on top right corner, and select settings. In the subsequent page, click SSH and GPG keys option. This will open up the SSH key page. Click on the New SSH key. In the "Title" field, add a descriptive label for the new key. Paste your key into the "Key" field.

  4. Clone the Repository

    Open VS Code (or any IDE/CLI which has command prompt etc.). Go to the directory in which you want to clone, using cd commands, and type the below line. git config --global github.user yourGitUserName git config --global user.email your_email git clone [email protected]:yourGitUserName/YourRepoName.git

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

    ssh-keygen -t rsa -b 4096 -C " [email protected]"

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

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

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

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

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

    输入密码(空表示没有密码):[输入密码]再次输入相同的密码:[再次输入密码]

  2. 将密钥添加到 SSH 代理

    在 Git Bash 中键入以下内容(99999 只是一个示例)以查看代理是否已启动并正在运行。eval $(ssh-agent -s) 代理 pid 99999

    然后输入这个。

    ssh 添加 ~/.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 [email protected]:yourGitUserName/YourRepoName.git

https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/