在git更新远程后,新的上游分支可见但不是原点 [英] After git update remote the new upstream branches are visible but not origin

查看:124
本文介绍了在git更新远程后,新的上游分支可见但不是原点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我的术语:上游是原始的apache回购(在github上)。 origin是我的apache repo分支(也在github上)。



执行以下操作后:

  git remote update 
git fetch

我看apache repo引用更新为包含两个新分支。

  [cloudera @ localhost delta] $ git remote update 
获取原点
获取上游
远程:计数对象:58,完成。
remote:压缩对象:100%(42/42),完成。
remote:合计58(delta 6),重用48(delta 6)
开箱对象:100%(58/58),完成。
从https://github.com/apache/spark
7e4a0e1..b060014 branch-0.9 - >上游/分支-0.9
1a0a2f8..952e0d6分支-1.0 - >上游/分支-1.0
* [新分支]分支-1.1 - > upstream / branch-1.1

请注意从上游创建的[新分支]。我不必做一个git分支-b。但是,起源新分支(其中有几个分支)呢?为什么这里的行为有所不同?



我的本​​地回购库(在单独的本地克隆中创建)上的任何新分支均未在此克隆中获取/创建。 / p>

那么如何取得原来的新分支?

更新根据建议by @VonC我没有

  git branch -avvv 

输出显示原始分支;

  delta 
* master
master
遥控器/原产地/ HEAD
遥控器/原产地/分支-0.5
..
遥控器/原产地/增量
遥控器/原产地/文档st
remotes / origin / strlen
remotes / upstream / branch-0.5
..
remotes / upstream / branch-1.1
remotes / upstream / master
..

所以我的困惑看起来更像是一个基本的/开始呃一:为什么

  $ git branch 
delta
* master

不显示eampe remotes / origin / docs ..我想我需要阅读 git分支 em>命令更多。



另一个更新 @ AD7Six在关于 git分支的回答中进一步解释了 vs git branch -r

解决方案

您需要从本地获取ustream,然后将这些分支你的fork( origin )。

  git fetch upstream 
git branch --set-upstream newBranch1 upstream / newBranch1
git push origin newBranch1

您的本地repo(克隆你的fork)是为了从上游获得新的提交/分支并将它们发布到原点的中间点。

从一个GitHub库到另一个没有直接复制。



用于从原始获取自己的分支,git fetch是足够的,请检查:

  git branch -avvv 

然后,您可以使用单线命令从远程追踪中创建本地分支:请参阅 git将所有分支从远程存储库中提取出来





git remote update自动在远程上游(apache)发现新的分支。

我不必做 git checkout -b 来创建它们。那么为什么上游和原产地之间的行为差​​异呢?



你应该看到相同的git a git fetch (或者 git fetch origin ):如果它们在结果中 git branch -avvv ,但是没有被您的下一个 git remote update 取回,这意味着它们已在您的本地克隆中



在这两种情况下(上游或原始),这些分支都是跟踪的分支,如 git branch -r r for remote)。



通过比较以下列表来检查它:




  • 本地分支: git分支

  • 远程(追踪)分支: git分支-r






请参阅 Atlassian的git fetch教程

  git fetch origin 




这将显示下载的分行:



  a1e8fb5 .45e66a4 master  - > origin / master 
a1e8fb5..9e8ab1c develop - > origin / develop
* [new branch] some-feature - > origin / some-feature




显示这些新远程分支的提交作为正方形而不是下面的图表中的圆圈。

正如您所看到的, git fetch 可让您访问另一个存储库的整个分支结构。 / p>


你看到创建的分支在 remotes 命名空间(在OP的情况下,远程/上游一个)


First my terminology: "upstream" is the original apache repo (on github). "origin" is my fork of the apache repo (also on github).

After executing the following:

git remote update
git fetch

I see the apache repo references updated to include two new branches.

[cloudera@localhost delta]$ git remote update
Fetching origin
Fetching upstream
remote: Counting objects: 58, done.
remote: Compressing objects: 100% (42/42), done.
remote: Total 58 (delta 6), reused 48 (delta 6)
Unpacking objects: 100% (58/58), done.
From https://github.com/apache/spark
   7e4a0e1..b060014  branch-0.9 -> upstream/branch-0.9
   1a0a2f8..952e0d6  branch-1.0 -> upstream/branch-1.0
 * [new branch]      branch-1.1 -> upstream/branch-1.1

Note the [new branch] created from the upstream. I did not have to do a "git branch -b". But what about the origin new branches (of which there are several)? Why the difference in behavior here?

None of the new branches on my local repo (created in a separate local clone) were fetch'ed/created in this clone.

So how to fetch the new branches in origin ?

UPDATE Based on suggestion by @VonC I did

git branch -avvv

The output DOES show the origin branches;

delta                            
* master                           
master
  remotes/origin/HEAD              
  remotes/origin/branch-0.5        
    ..
  remotes/origin/delta             
  remotes/origin/docs              st
  remotes/origin/strlen            
  remotes/upstream/branch-0.5      
   ..
  remotes/upstream/branch-1.1      
  remotes/upstream/master          
  ..

So my confusion then looks to be more of a basic/beginner one: why did

$ git branch
  delta
* master

Does not show for eampe remotes/origin/docs.. I guess I need to read up on the git branch command more here.

Another update @AD7Six has explained about further in his answer about the git branch vs git branch -r

解决方案

You need to fetch from ustream locally, then push those branches to your fork (origin).

git fetch upstream
git branch --set-upstream newBranch1 upstream/newBranch1 
git push origin newBranch1 

Your local repo (cloned of your fork) is the intermediate point in order to get new commits/branches from upstreams and publish them to origin.
There is no "direct replication" from one GitHub repo to another.

For fetching your own branches from origin, git fetch is enough, check with:

git branch -avvv

Then you can use a one-liner command to create local branches from the remote tracking ones that were fetched: see "git pull all branches from remote repository".


the "git remote update" automatically found new branches on the remote upstream (apache).
I did not have to do "git checkout -b" to create them.

So then why the difference in behavior between the upstream and the origin?

You should see the same git a git fetch (or git fetch origin): if they are in the result of a git branch -avvv, but were not fetched by your next git remote update, that means they were already present in your local clone.

In both cases, (upstream or origin), those branches are remotes tracking ones, as seen in git branch -r (r for remote).

You can check it by comparing the list of:

  • local branches: git branch
  • remote (tracking) branches: git branch -r

See more in this git fetch tutorial from Atlassian:

git fetch origin

This will display the branches that were downloaded:

a1e8fb5..45e66a4 master -> origin/master
a1e8fb5..9e8ab1c develop -> origin/develop
* [new branch] some-feature -> origin/some-feature

The commits from these new remote branches are shown as squares instead of circles in the diagram below.
As you can see, git fetch gives you access to the entire branch structure of another repository.

The branches you see "created" are registered in the "remotes" namespace (in the OP case, the "remotes/upstream" one)

这篇关于在git更新远程后,新的上游分支可见但不是原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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