After git remote update, new upstream branches are visible but not natively

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

After doing the following:

git remote update
git fetch

      

I can see the updated apache repository links 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

      

Notice the [new branch] created from the upstream. I didn't need to do a "git -b branch". But what about the new origin branches (of which there are several)? Why is there a difference in behavior?

None of the new branches of my local repo (created in a separate local clone) have been created / created in this clone.

So how do you get new branches in the source?

UPDATE Based on @ VonC's suggestion, I did

git branch -avvv

      

DOES result shows branches of origin,

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 seems to be more basic / beginner: why

$ git branch
  delta
* master

      

Not showing up for eampe remotes / origin / docs .. I think I need to read more of the git branch command here.

Another update @ AD7Six explained further in his answer about branching git vs git -r

+3


source to share


3 answers


You need to fetch from your local source, then pipe those branches to your fork ( origin

).

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

      

Your local repo (cloned from your fork) is an intermediate point to get new commits / branches from upstream and publish them at the beginning.
There is no "direct replication" from one GitHub repo to another.

For fetching your own branches from source, git fetch is sufficient, check with:

git branch -avvv

      

You can then use the single-layer command to create local branches from the remote tracks that have been checked out: see git pull all branches from the remote repository .


"git remote update" automatically detected new branches on the remote upstream (apache).
I didn't have to do " git checkout -b

" to create them.

So why is there a difference in behavior between ascending and ascending?

You should see the same git a git fetch

(or git fetch origin

): if they are in the result git branch -avvv

, but were not picked by your next git remote update

, that means they were already present in your local clone .

In both cases (upstream or upstream), these branches are tracking remotes as shown in git branch -r

( r

for remote).



You can check this by comparing the list:

  • local branches: git branch

  • remote (tracking) branches: git branch -r


More details in this git fetch tutorial from Atlassian :

git fetch origin

      

This will display the loaded branches:

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

      

Entries from these new deleted branches are shown as squares instead of circles in the diagram below.
As you can see, it git fetch

gives you access to the entire branch structure of another repository.

https://gp1.wac.edgecastcdn.net/8029C4/wac-small/wac/landing/git/tutorial/remote-repositories/pageSections/00/contentFullWidth/0/tabs/01/pageSections/02/contentFullWidth/00/ imageBinary / git-tutorial-repos-fetch.png

The branches you see "created" are registered in the " remotes

" namespace (in the OP's case, " remotes/upstream

")

+2


source


branch

Git only shows local branches

Running git branch

with no arguments will only show local branches:

-> git branch
* develop
  master

      

To display only remote branches use the parameter --remote

(or -r

):

-> git branch --remote
  origin/HEAD -> origin/master
  origin/develop
  origin/master

      



To show all branches use the parameter --all

(or -a

):

-> git branch --all
* develop
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/master

      

All commands can be combined with an advanced option for more information:

-> git branch -vv
* develop 5cb42f9 [origin/develop: ahead 3] make logging configurable
  master  77de2a8 [origin/master: ahead 7] Merge branch 'develop'

      

For more information on branch command arguments, see the documentation

+3


source


Fetching from remotes only updates your remote links for example. branches like origin/master

. Git does not automatically create local branches that can be used to update remote branches.

To create a local branch from any of the remote branches, you need to do this -

git checkout -b newLocalBranch <remote_name>/<remote_branch_name>

      

Now the newLocalBranch branch is said to track the branch in your repository. Thus, you can now work with the local newLocalBranch and use it to push your new commits to the remote branch with -

git push <remote_name> newLocalBranch:<remote_branch_name>

      

+2


source







All Articles