【问题标题】:Remote Pushurl won't work远程 Pushurl 不起作用
【发布时间】:2012-05-14 21:48:03
【问题描述】:

我在我的项目中使用 GIT。现在我想把它和github集成,所以我创建了一个远程:

git remote add github https://WouterJ@github.com/WouterJ/project.git

但是现在我需要填写一个密码来获取,这是我不想要的。所以我决定使用不同的 url 来获取:

git remote set-url github http://github.com/WouterJ/project.git
git remote set-url --push github https://WouterJ@github.com/WouterJ/project.git

如果我运行git remote -v,我会得到:

$ git remote -v
github  http://github.com/WouterJ/project.git (fetch)
github  https://WouterJ@github.com/WouterJ/project.git (push)
origin  http://github.com/WouterJ/project.git (fetch)
origin  http://github.com/WouterJ/project.git (push)

正是我想要的,我想。但是当我推送时,我需要填写我的用户名。为什么?如果我填写后直接推送到 url,则效果很好:

git push https://WouterJ@github.com/WouterJ/project.git master

有效,但是

git push github master

没用


我还使用git config 设置了不同的推送网址:

git config remote.github.pushurl https://WouterJ@github.com/WouterJ/project.git

如果我从配置中获取 pushurl,它看起来是正确的:

$ git config remote.github.pushurl
https://WouterJ@github.com/WouterJ/project.git

同时查看 .git/config 文件,看起来一切都正确。


我在这里遗漏了什么吗?它是一个错误吗?我用的是Git1.7.4,有错吗?

【问题讨论】:

    标签: git github git-remote


    【解决方案1】:

    为了推送到 https GitHub 地址,唯一缺少的部分是您的 ~/.netrc 文件(或 Windows 上的 %HOME%/_netrc 文件),其中包含您的 GitHub 凭据。

    见“Git - How to use .netrc file on windows to save user and password”。

    machine github.com
    login <login_github>
    password <password_github>
    

    在“Syncing with github”查看其他设置。

    【讨论】:

    • 感谢您的评论,但我不想保存密码。问题是当我在git push 命令中使用url 时,我只需要输入密码。输入网址或使用遥控器pushurl 有什么区别?我理解pushurl 错了吗?
    • @WouterJ git remote set-url --push 和 git config remote.github.pushurl 应该是等价的。您是否有可能在另一个配置文件(全局或系统文件,而不是本地配置文件)中定义了 github?
    • 这两种技术都行不通。 url 保存在正确的文件中。如果我将该 url 更改为本地 repo 它可以工作并且 url 本身可以工作,但是 pushurl 的用户 SSH 部分将无法工作。我对 git add configs 也不太了解,所以是全局的还是系统的?什么意思?
    • 如果我输入 git config --get-all remote.github.pushurl 我只会得到我为项目设置的那个。所以看起来另一个配置文件中没有 github 远程。我已经通过使用_netrc 文件解决了这个问题(但我可以只保存用户名而不保存密码吗?)
    【解决方案2】:

    我已经找到了如何解决这个问题,所以提出我自己的问题:

    诀窍是上传到 Git1.7.8(或更高版本)。现在,您可以使用相同的设置并没有 _netrc 文件:

    $ git push github master
    Password for 'https://WouterJ@github.com/':
    
    $ git fetch github
    fetching....
    

    所以看起来这个 bug 在 Git1.7.8 (Release Notes) 中已经修复了

    【讨论】:

    • 优秀。 +1。我以为你使用的是 Git1.7.4(虽然它已经高于 1.7.0)
    • 等等,我输入了 Git1.7.0,但意思是 Git1.7.10.1(最新的稳定版本)。谢谢,我会修改的
    • 好的,现在我明白了;) 我正在使用 1.7.9 和 1.7.10 进行测试,但无法重现您的问题,因此可以确认。
    • @VonC,我做了更多的研究,看起来这个错误在 1.7.8 中已修复 (Release Notes)
    猜你喜欢
    • 1970-01-01
    • 2012-08-28
    • 2014-02-05
    • 2016-02-02
    • 2015-12-02
    • 2013-08-12
    • 2015-04-05
    • 2014-01-01
    相关资源
    最近更新 更多