Remote Pushurl won't work

懵懂的女人 提交于 2019-12-12 09:51:47

问题


I'm using GIT for my projects. Now I want to integrate it with github, so I created a remote:

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

But now I need to fill in a password for fetching, something that I don't want. So I decided to use a different url for fetching:

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

If I run git remote -v I get this:

$ 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)

Exactly want I want, I thought. But when I do a push I need to fill in my Username. Why? If I push directly to the url if filled in it works perfectly:

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

Works, but

git push github master

Won't work


I also used the git config to set a different push url:

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

And if I get the pushurl from the config it looks like it is correct:

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

Also looking at the .git/config file it looks like everything is correct.


Am I missing something here? Is it a bug? I use Git1.7.4, is that wrong?


回答1:


I have found how you can solve this, so to aswer my own question:

The trick is to upload to Git1.7.8 (or higher). Now you get this with the same settings and without a _netrc file:

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

$ git fetch github
fetching....

So it looks like the bug is fixed in Git1.7.8 (Release Notes)




回答2:


The only missing piece, in order to push to an https GitHub address, is your ~/.netrc file (or %HOME%/_netrc file on Windows) with your GitHub credentials in it.

See "Git - How to use .netrc file on windows to save user and password".

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

See other settings at "Syncing with github".



来源:https://stackoverflow.com/questions/10464250/remote-pushurl-wont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!