简体   繁体   English

如何在git中撤消跟踪远程分支?

[英]How do I undo tracking a remote branch in git?

I've accidentally unhitched my master branch from tracking origin master I think. 我不小心从跟踪原点大师那里意外地取消了我的主分支。 It used to be that I could run git pull and git push and it would know that I meant git push origin master but now it does not, and I think it's tracking a different branch because git push origin master works fine (everything up to date) and git push tells me it can't fast-forward changes. 以前我可以运行git pullgit push ,它会知道我的意思是git push origin master但现在它没有,我认为它跟踪不同的分支,因为git push origin master工作正常(一切都是最新的)和git push告诉我它不能快进变化。

Here's what my git branch -a looks like: 这是我的git branch -a样子:

ianstormtaylor:nib Storm$ git branch -a
* master
  original
  transforms
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/sizing
  remotes/origin/transforms

Not sure if that remotes/origin/HEAD -> origin/master is the part that is messed up. 不确定remotes/origin/HEAD -> origin/master是否是混乱的部分。

I think this all resulted from a git merge origin sizing call when i meant to do git merge sizing (while on master). 我认为这一切都源于git merge origin sizing调用,当我打算进行git merge sizing (在master上)。

Anyone know what's going on and is able to help? 任何人都知道发生了什么,并能够提供帮助吗? I'd just like to get back to the default remote-tracking setup that git clone creates. 我只想回到git clone创建的默认远程跟踪设置。

All you need in you git config (do git config -e to edit) is the following: 您需要的所有Git配置(执行git config -e编辑)如下:

[remote "origin"]
   fetch = +refs/heads/*:refs/remotes/origin/*
   url = /Users/me/test.git
[branch "master"]
   remote = origin
   merge = refs/heads/master

If it is there, git push from master, will be equivalent to git push origin master 如果它存在, git push从master,将相当于git push origin master

The remotes/origin/HEAD -> origin/master part just says that HEAD of remote origin is master branch ( of origin) and is fine. remotes/origin/HEAD -> origin/master部分只是说远程原点的HEAD是主分支(原点)并且很好。

I've had this happen a few times - and while I'm not sure of the exact cause I don't believe it's from a mistake that you've made. 我已经发生了几次这种情况 - 虽然我不确定确切的原因,但我不相信这是因为你犯了一个错误。 Rather it's simply that git pull is a shortcut to the most recent remote branch and it's forgotten what the most recent branch is. 相反,它只是git pull是最近一个远程分支的快捷方式 ,它忘记了最新的分支是什么。

Executing a git pull origin master usually updates the setting and resets everything. 执行git pull origin master通常会更新设置并重置所有内容。

I suppose you could edit the .git/config file or set the config using 我想你可以编辑.git / config文件或使用设置配置

git config branch.master.remote origin
git config branch.master.merge refs/heads/master

Alternatively, recreate the master branch using the -t ( --tracking ) option 或者,使用-t (-- --tracking )选项重新创建主分支

Both should result in a section similar to this in your .git/config : 两者都应该导致.git/config此类似的部分:

[branch "master"]
    remote = origin
    merge = refs/heads/master

You can use 您可以使用

git branch --set-upstream my_branch origin/my_branch git branch --set-upstream my_branch origin / my_branch

Alternatively 另外

git push -u origin my_branch git push -u origin my_branch

See Git: Why do I need to do --set-upstream all the time? 请参阅Git:为什么我需要一直进行--set-upstream for more detail. 了解更多细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM