无法在git存储库中推送文件

时间:2019-08-26 23:22:35

标签: github

我正在尝试使用此命令将使用git bash的文件推送到在线git存储库中。

$ git push -u origin master https://github.com/SMAmmar/git-test.git

但是使用它后,我得到了这个错误

  

致命:无效的refspec'https://github.com/SMAmmar/git-test.git'

如何解决此问题?我是使用github的新手,所以请详细说明你们告诉我要做的事情。 enter image description here

2 个答案:

答案 0 :(得分:0)

git push没有URL。相反,它使用您先前设置的远程存储库的名称,即origin和要推送的分支。当您origin存储库时,git clone会自动设置。

如果运行git remote -v,您应该会看到类似以下内容的内容:

origin  https://github.com/SMAmmar/git-test.git (fetch)
origin  https://github.com/SMAmmar/git-test.git (push)

如果看到其他网址,请使用git remote set-url origin https://github.com/SMAmmar/git-test.git指向该网址的origin

然后git push origin master说将您的master分支推送到master所标识的存储库origin上的https://github.com/SMAmmar/git-test.git分支。

另请参见

答案 1 :(得分:0)

来自git push

git push <repository> [<refspec>…]
  

作为推送操作目标的“远程”存储库。
  此参数可以是URL (请参见下面的GIT URLS部分)或远程服务器的名称(请参见下面的REMOTES部分)。

是的,git push 可以使用网址

但是顺序很重要:

  • 您推送的位置(URL或远程名称)
  • 你推动什么

在您的情况下:

git push -u origin master 

git push -u https://github.com/SMAmmar/git-test.git master 

originhttps://github.com/SMAmmar/git-test.git都不是

首选第一种形式。一旦第一个命令生效,简单的git push就足够了。