git push 错误:请求的 URL 返回错误 400
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35827033/
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
git push error: the requested URL returned error 400
提问by Alex Reds
I am new to Git and I am trying to to push a Java project to Github using Git Bash.
我是 Git 的新手,我正在尝试使用 Git Bash 将 Java 项目推送到 Github。
This is what I did:
这就是我所做的:
created a Blog repository in GitHub
in Git Bash
$ cd C:/Users/Alessandro/workspace/BLOG
$ echo "# Blog" >> README.md
$ git add –-all
$ git commit -m "Initial commit"
$ git remote add origin https://github.com/alerossi82/Blog
$ git push -u origin master
在 GitHub 中创建了一个博客存储库
在 Git Bash 中
$ cd C:/Users/Alessandro/workspace/BLOG
$ echo "# Blog" >> README.md
$ git add --all
$ git commit -m "初始提交"
$ git remote add origin https://github.com/alerossi82/Blog
$ git push -u origin master
But when I do the push, this is the result I get:
但是当我进行推送时,这是我得到的结果:
fatal: unable to access 'https://github.com/username/repository/': The requested URL returned error: 400
致命:无法访问“ https://github.com/username/repository/”:请求的 URL 返回错误:400
I read somewhere this is could be a login problem, but I checked my config in GitBash and the username and email match with GitHub. When I commit the push, I I am logged in to my GitHub account and I do not receive any insert password request from GitBash.
我在某处读到这可能是登录问题,但我在 GitBash 中检查了我的配置,并且用户名和电子邮件与 GitHub 匹配。当我提交推送时,我登录到我的 GitHub 帐户并且我没有收到来自 GitBash 的任何插入密码请求。
Then I tried to push the project directly from Eclipse, but this failed as well, in fact when I push the changes I receive the message: - master >> master [rejected - non-fast-forward]
然后我尝试直接从 Eclipse 推送项目,但这也失败了,实际上当我推送更改时我收到消息:- master >> master [rejected - non-fast-forward]
I am totally lost, I think all the step are correct however it looks like my local and remote repositories don't want to talk to each other, and I have no idea why.
我完全迷失了,我认为所有步骤都是正确的,但是看起来我的本地和远程存储库不想相互交谈,我不知道为什么。
Any help?
有什么帮助吗?
回答by CodeWizard
You missed the
你错过了
git add . -A
before the commit so no files were added
在提交之前所以没有添加文件
cd C:/Users/Alessandro/workspace/BLOG
echo "# Blog" >> README.md
# Here you need to run the git add command
git add -A .
git commit -m "Initial commit"
git remote add origin https://github.com/alerossi82/Blog
git push -u origin master
回答by m000
You missed the .git
part, which is important. The url you are adding corresponds to the web page you view on GitHub, not the git repository. You should do:
你错过了.git
重要的部分。您添加的 url 对应于您在 GitHub 上查看的网页,而不是 git 存储库。你应该做:
$ git remote add origin https://github.com/alerossi82/Blog.git
$ git remote add origin https://github.com/alerossi82/Blog.git
Also, if this is your own repository, you probably want to use the SSH url instead of the HTTPS url:
$ git remote add origin [email protected]:alerossi82/Blog.git
此外,如果这是您自己的存储库,您可能希望使用 SSH url 而不是 HTTPS url:
$ git remote add origin [email protected]:alerossi82/Blog.git
This will make your everyday life easier, as you can use an ssh key for authentication instead of typing your GitHub password every time. More info on GitHub urls here.
这将使您的日常生活更轻松,因为您可以使用 ssh 密钥进行身份验证,而无需每次都输入您的 GitHub 密码。有关 GitHub 网址的更多信息,请点击此处。
回答by Farhad Faghihi
You should fist check what files, you have changes and are ready to be committed, using :
您应该首先检查哪些文件,您有更改并准备提交,使用:
git status
If you saw any changed files, stage them for committing, using :
如果您看到任何更改的文件,请使用以下命令暂存它们以进行提交:
git add .
Then commit your changes.
然后提交您的更改。
git commit -m "your commit message"
And finally :
最后:
git push -u origin master
回答by Awesome
Had a similar problem and it turned out that I had some issues with my .gitconfig
file since I had earlier run git config --global url."[email protected]:".insteadOf "https://github.com/"
and later git config --global url."https://github.com/".insteadOf "[email protected]:"
which added both lines to my .gitconfig file. So all I did was clean my .gitconfig file using vim in my terminal(Iterm)
:
有一个类似的问题,结果我的.gitconfig
文件有一些问题,因为我之前运行过git config --global url."[email protected]:".insteadOf "https://github.com/"
,后来git config --global url."https://github.com/".insteadOf "[email protected]:"
将这两行都添加到了我的 .gitconfig 文件中。所以我所做的就是在终端中使用 vim 清理我的 .gitconfig 文件(Iterm)
:
$ vi $HOME/.gitconfig
$ vi $HOME/.gitconfig
Then removed the unwanted lines from the .gitconfig
file using vim editor. Hope it helps.
然后.gitconfig
使用 vim 编辑器从文件中删除不需要的行。希望能帮助到你。