git push error:请求的URL返回错误400

时间:2016-03-06 12:51:56

标签: git github git-push

我是Git的新手,我正在尝试使用Git Bash将Java项目推送到Github。

这就是我所做的:

  • 在GitHub中创建了一个Blog存储库

  • 在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

但是当我做推动时,这就是我得到的结果:

致命:无法访问' https://github.com/username/repository/':请求的网址返回错误:400

我在某处读到这可能是登录问题,但我在GitBash中检查了我的配置,用户名和电子邮件与GitHub匹配。 当我提交推送时,我登录到我的GitHub帐户,我没有从GitBash收到任何插入密码请求。

然后我尝试直接从Eclipse推送项目,但这也失败了,事实上当我推送更改时,我收到消息: - master>>主人[拒绝 - 非快进]

我完全迷失了,我认为所有步骤都是正确的,但看起来我的本地和远程存储库不想互相交谈,我不知道为什么。

任何帮助?

4 个答案:

答案 0 :(得分:0)

你错过了

 git add . -A
在提交之前

因此没有添加文件

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

答案 1 :(得分:0)

你错过了.git部分,这很重要。您添加的URL对应于您在GitHub上查看的网页,而不是git存储库。你应该这样做:

$ git remote add origin https://github.com/alerossi82/Blog.git

此外,如果这是您自己的存储库,您可能希望使用SSH网址而不是HTTPS网址: $ git remote add origin git@github.com:alerossi82/Blog.git

这将使您的日常生活更轻松,因为您可以使用ssh密钥进行身份验证,而不是每次都输入您的GitHub密码。有关GitHub的更多信息,请here

答案 2 :(得分:0)

您应该使用以下方法检查哪些文件,您有更改并准备好提交:

.o

如果您看到任何已更改的文件,请使用以下命令将其暂存以进行提交:

git add *

然后提交您的更改。

git status

最后:

git add .

答案 3 :(得分:0)

发生了类似的问题,结果发现我的.gitconfig文件存在一些问题,因为我以前运行过git config --global url."git@github.com:".insteadOf "https://github.com/",后来又运行过git config --global url."https://github.com/".insteadOf "git@github.com:",这两个行都添加到了.gitconfig文件中。因此,我要做的就是在终端机(Iterm)中使用vim清理.gitconfig文件:

$ vi $HOME/.gitconfig

然后使用vim编辑器从.gitconfig文件中删除不需要的行。希望对您有所帮助。

相关问题