"origin"似乎不是一个git仓库。

4

我按照vogella GIT教程中的第17节练习“使用(本地)远程存储库”进行操作。执行第17.3步时,我遇到了以下错误:

The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

git push --set-upstream ../remote-repository.git master

执行的步骤是:
   $repo01>git clone --bare . ../remote-repository.git
   Cloning into bare repository '../remote-repository.git'...
   done.
   $mkdir repo02
   $\repo02>git clone ../remote-repository.git .
   Cloning into '.'...
   done.
   $\repo01>git status
   On branch master
   Changes not staged for commit:
   (use "git add <file>..." to update what will be committed)
   (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   test01
        modified:   test02.txt

    no changes added to commit (use "git add" and/or "git commit -a")
  $repo01>git commit -a -m "Some changes"
  $\repo01>git push ../remote-repository.git
  fatal: The current branch master has no upstream branch.
  To push the current branch and set the remote as upstream, use

    git push --set-upstream ../remote-repository.git master

什么可能是原因?
2个回答

4
正如git所告诉你的那样:当前分支master没有上游分支。因此,git不知道应该将您的更改推送到remote-repository的哪个分支。
我无法复制这个问题;如果我执行您的步骤,则会设置上游分支。但是,要解决此问题,您可以按照git告诉您的做法:git push --set-upstream ../remote-repository.git master。这告诉git您当前正在使用的分支(本地master)默认从您的远程存储库的master分支中拉取并推送。如果一旦设置,将来推送将自动知道要推送到哪里。
您在问题中提供的命令之外还做了其他事情吗?
编辑:我可能无法重现此问题,因为我的push.default自定义设置:我建议将其设置为current,方法是$ git config --global push.default current。这意味着git仅推送当前分支,并且如果存在具有相同名称的远程分支,则自动推送到远程分支。有关详细信息,请参见here上的push.default部分。

我没有做任何教程之外的操作,所以我不知道为什么上游分支没有自动设置。建议的git命令对我有效。 - SarahData
根据我上面的编辑说明,根据你的push.default配置,你的上游分支显然没有自动设置。 - kowsky
我在文档中找到了这个内容: "当推送到一个与你通常拉取不同的远程仓库时,将工作目录设置为当前状态。这是最安全的选项,适合初学者。这种模式已成为Git 2.0的默认设置。" 我的Git版本是2.9.2。因此,它应该已经设置为默认值了。 - SarahData
您可以使用 $ git config --global push.default 进行检查。 - kowsky
@SarahM:对于push.defaultsimple设置要像current设置一样工作,仍然必须配置上游。更准确地说,必须配置branch.<branch>.remote。如果您还在学习Git,我不建议更改push.default;只需使用--set-upstream选项,它可以缩写为-u,或者使用git push <repository> <branch>:<branch>,即将分支名称写两次,并在中间加上冒号。两个带有冒号的名称形式意味着“我的分支是左侧的名称,请请求者使用右侧的名称设置他们的分支”。 - torek

-1
git push origin master

origin 是你的远程 Git 分支名称,master 是你的本地分支。


1
“origin” 是您本地区域对远程仓库的别名。 - smarber
我的情况中,远程源指向克隆的存储库repo01,对吗?master是我的本地分支是什么意思?你是指repo01 master吗?否则,我执行了命令但没有起作用,我得到了:'origin'不似乎是一个git存储库致命错误:无法从远程存储库读取。 - SarahData
1
https://dev59.com/02Ag5IYBdhLWcg3wm776 - ashanrupasinghe
1
https://dev59.com/dm025IYBdhLWcg3wT0Hq - ashanrupasinghe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接