'起源'并不是一个git存储库

时间:2017-03-01 09:55:59

标签: git

我跟着vogella tutorial about 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 个答案:

答案 0 :(得分:4)

正如git告诉你的那样:The current branch master has no upstream branch.因此,git不知道你的remote-repository哪个分支应该推动你的更改。

我无法重现这一点;如果我执行您的步骤,则设置上游分支。但是,为了解决这个问题,你可以完全按照git告诉你的那样做:git push --set-upstream ../remote-repository.git master。这告诉git默认情况下,您当前正在处理的分支(您的本地master)从并远程推送到远程存储库的master分支。如果一旦设置,push将自动知道将来推送到哪里。

除了您在问题中提供的命令外,您还做了什么吗?

编辑:由于push.default的自定义设置,我可能无法重现这一点:我建议将其设置为$ git config --global push.default current的最新版本。这意味着git只推送当前分支并自动推送到具有相同名称的远程分支(如果存在)。有关详细信息,请参阅push.default部分的here

答案 1 :(得分:0)

git push origin master

origin是你的远程git分支名称, master是你当地的分支。