git 如何使主分支跟踪?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5112336/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:06:27  来源:igfitidea点击:

How to make the master branch track?

git

提问by Malvolio

I cloned a repository and was working in the master branch. There was a consistent problem: git push(and git push) didn't work and gave long, uninterpretable error message. Through trial-and-error, I found git push origin masterdid the push correctly. But now I've noticed something odd:

我克隆了一个存储库并在 master 分支中工作。有一个一致的问题:(git pushgit push)不起作用,并给出了长长的、无法解释的错误消息。通过反复试验,我发现git push origin master推送正确。但现在我注意到一些奇怪的事情:

$ git config push.default tracking
$ git push
fatal: The current branch master is not tracking anything.

WTF? I thought if you cloned a repository, the master was automatically tracked. Anyway, my real questions are

跆拳道?我想如果你克隆了一个存储库,主人会被自动跟踪。无论如何,我真正的问题是

  1. How am I supposed to create a clone so the branches are tracked?
  2. What are the consequences (other than current) of nothaving tracking?
  3. How do I fix the current situation, so that my branch does track the remote?
  1. 我应该如何创建一个克隆以便跟踪分支?
  2. 没有跟踪的后果(当前除外)是什么?
  3. 如何解决当前情况,以便我的分支跟踪遥控器?

EDITMy local repository was acting strangely in other ways; most notably: I couldn't create remote branches. I put it aside and made a fresh clone, and it's acting strangely in fresh ways.

编辑我的本地存储库在其他方面表现得很奇怪;最值得注意的是:我无法创建远程分支。我把它放在一边,做了一个新的克隆,它以新鲜的方式表现得很奇怪。

First, masteris tracking (yeah). Second, I was able to make a remote branch, but it's odd.

首先,master是跟踪(是的)。其次,我能够创建一个远程分支,但这很奇怪。

Ratatouille $ git push origin origin:refs/heads/premium
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]:gamecrush/Ratatouille.git
 * [new branch]      origin/HEAD -> premium
Ratatouille $ git branch -r
  origin/HEAD -> origin/master
  origin/master
  origin/premium

Ratatouille is the name of the remote repo, of course. The strange point: what is that ->there for? It seems to be new and it doesn't show up for the old local repo or other clones of the remote.

当然,料理鼠王是远程仓库的名称。奇怪的一点:那是->为了什么?它似乎是新的,它不会出现在旧的本地存储库或远程的其他克隆中。

But now branching and tracking work as advertised.

但现在分支和跟踪工作正如宣传的那样。

回答by Arrowmaster

What is your branch.autosetupmergeset to? By default it should have setup the branch tracking when you cloned.

你的branch.autosetupmerge设置是什么?默认情况下,它应该在您克隆时设置了分支跟踪。

Try setting the upstream for the branch with this to make the branch track the remote.

尝试使用此设置分支的上游以使分支跟踪远程。

git branch --set-upstream master origin/master

回答by Dave Bettin

An alternative: to set the master to track the remote, during your first push execute:

另一种选择:设置主跟踪远程,在您第一次推送期间执行:

git push -u origin master

The -uwill do the same as --set-upstream. After, run git branch -vvto see a list of branches including their tracking branches.

-u会做的一样--set-upstream。之后,运行git branch -vv以查看分支列表,包括其跟踪分支。

回答by Arturo Herrero

Other alternative:

其他选择:

git branch --set-upstream-to=origin/master