git:从公共仓库设置单个跟踪远程 [英] git: setting a single tracking remote from a public repo

查看:103
本文介绍了git:从公共仓库设置单个跟踪远程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对远程分支感到困惑.

I am confused with remote branches.

我的本​​地仓库:

(local) ---A---B---C-master

我的远程仓库(称为int):

My remote repo (called int):

(int) ---A---B---C---D---E-master

我想要做的是设置本地存储库的master分支以跟随int的master分支. 本地存储区:

What I want to do is to setup the local repo's master branch to follow that of int. Local repo:

(local) ---A---B---C---D---E-master-remotes/int/master

以便当int更改为:

(int) ---A---B---C---D---E---F-master

我可以从本地仓库的主服务器上运行git pull并获取

I can run git pull from the local repo's master and get

(local) ---A---B---C---D---E---F-master-remotes/int/master

这是我尝试过的:

  1. git fetch int将我的所有int分支带入远程分支.由于int可能有数百个分支,所以这可能会变得凌乱.

  1. git fetch int gets me all the branches of int into remote branches. This can get messy since int might have hundreds of branches.

git fetch int master将提交提交给我,但没有引用,只有FETCH_HEAD.也没有远程分支.

git fetch int master gets me the commits, but no ref to it, only FETCH_HEAD. No remote branch either.

git fetch int master:new_master可以使用,但是我不想每次更新都使用新名称,并且没有设置任何远程分支.

git fetch int master:new_master works but I don't want a new name every time I update, and no remote branch is setup.

git pull int master可以满足我的要求,但是仍然没有远程分支机构设置.我觉得这样做是可以的(这是我现在最好的),但是我在这里和那里读到,使用远程设置使用git pull就足够了.

git pull int master does what I want, but there is still no remote branch setup. I feel that it is ok to do so (that's the best I have now), but I read here and there that with the remote setup it is enough with git pull.

git branch --track new_master int/master,根据 http://www.gitready.com/beginner/2009/03/09/remote-tracking-branches.html .我得到无效的对象名称:int/master". git remote -v确实向我展示了int已定义并指向正确的位置(1.有效).我想念的是int/master分支,这正是我想要得到的.

git branch --track new_master int/master, as per http://www.gitready.com/beginner/2009/03/09/remote-tracking-branches.html . I get "not a valid object name: int/master". git remote -v does show me that int is defined and points at the correct location (1. worked). What I miss is the int/master branch, which is precisely what I want to get.

git fetch in master:int/master.好了,创建了int/master,但是没有远程.

git fetch in master:int/master. Well, int/master is created, but is no remote.

总而言之,我尝试了一些运气不好的东西.我希望2给我远程分支以控制回购int.

So to summarize, I've tried some stuff with no luck. I would expect 2 to give me the remote branch to master in the repo int.

我现在使用的解决方案是选项3.

The solution I use now is option 3.

我读过某个地方,您可以手动更改一些配置文件,但这并不麻烦吗?

I read somewhere that you could change some config file by hand, but isn't that a bit cumbersome?

编辑配置文件的繁琐"方式确实有效:

The "cumbersome" way of editting the config file did work:

[branch "master"]
    remote = int
    merge = master

可以从命令行完成:

$ git config branch.master.remote int

$ git config branch.master.merge master

任何原因为何上述选项2不会自动执行该操作? 即使在这种情况下,git pull也会从远程获取所有分支.

Any reason why option 2 above wouldn't do that automatically? Even in that case, git pull fetches all branches from the remote.

推荐答案

请确保首先在工作树中没有当前的工作.

Make sure you don't have any current work in your working tree first.

然后尝试一个(使用Git1.7.0或更高版本):

Then try a (with Git1.7.0 or more):

git fetch int master
git branch --force -- set-upstream master int/master

这篇关于git:从公共仓库设置单个跟踪远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆