如何从命令行使用“git pull”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9830299/
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 13:17:21  来源:igfitidea点击:

How to use 'git pull' from the command line?

gitcommand-linesshgithubnant

提问by Chev

We were using a build script to automate our publishing process and it was working with SVN but now we are using Git and need to do some command line operations to pull from our remote repository.

我们使用构建脚本来自动化我们的发布过程,它与 SVN 一起工作,但现在我们使用 Git 并且需要执行一些命令行操作来从我们的远程存储库中提取。

I was able to follow the guide hereand using the Git bash it works great. However, I need to perform these tasks from the Windows command line so that they can be executed by the script.

我能够按照此处的指南进行操作并使用 Git bash 效果很好。但是,我需要从 Windows 命令行执行这些任务,以便脚本可以执行它们。

git pull origin masterworks in the Git bash.

git pull origin master在 Git bash 中工作。

cd "c:\program files (x86)\git\bin
git --git-dir=path\to\.git pull origin master 

fails with an error

失败并出现错误

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

权限被拒绝(公钥)。
致命:远端意外挂断

Obviously my SSH key is not being used properly or something. I'm so new to this that I really have no clue what to do.

显然我的 SSH 密钥没有被正确使用或什么的。我对此很陌生,我真的不知道该怎么做。

采纳答案by manojlds

Try setting the HOME environment variable in Windows to your home folder (c:\users\username).

尝试将 Windows 中的 HOME 环境变量设置为您的主文件夹 ( c:\users\username)。

( you can confirm that this is the problem by doing echo $HOMEin git bash and echo %HOME%in cmd - latter might not be available )

(您可以通过echo $HOME在 git bash 和echo %HOME%cmd 中执行来确认这是问题所在 - 后者可能不可用)

回答by eckes

Open up your git bash and type

打开你的 git bash 并输入

echo $HOME

This shall be the same folder as you get when you open your command window (cmd) and type

这应该与您打开命令窗口(cmd)并键入时获得的文件夹相同

echo %USERPROFILE%

And – of course – the .sshfolder shall be present on THAT directory.

而且——当然——.ssh文件夹应该存在于那个目录中。

回答by Vamshi

One more option is to add the path of the privatekey file like this in terminal:

另一种选择是在终端中像这样添加私钥文件的路径:

ssh-add "path to the privatekeyfile"

ssh-add “私钥文件的路径”

and then execute the pull command

然后执行pull命令