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

查看:16
本文介绍了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

我想要做的是设置本地 repo 的 master 分支以遵循 int 的分支.本地仓库:

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 变为:

So that when int changes to:

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

我可以从本地 repo 的 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 给我远程分支以掌握 repo 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天全站免登陆