After git update remote the new upstream branches are visible but not origin

后端 未结 3 980
梦谈多话
梦谈多话 2021-01-13 20:47

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 followi

相关标签:
3条回答
  • 2021-01-13 21:23

    Git branch only shows local branches

    Running git branch with no arguments, will show only local branches:

    -> git branch
    * develop
      master
    

    To show only remote branches use the --remote (or -r) option:

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

    To show all branches use the --all (or -a) option:

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

    All commands can be combined with the verbose option to get more info:

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

    For more info on the branch command arguments, see the documentation

    0 讨论(0)
  • 2021-01-13 21:38

    Fetching from the remotes only updates your remote references eg. branches like origin/master. Git does not automatically create local branches that you can use to update your 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 branch newLocalBranch is said to be tracking the branch on your repository. So you can now work on your local newLocalBranch and use it to push your new commits to the remote branch using -

    git push <remote_name> newLocalBranch:<remote_branch_name>
    
    0 讨论(0)
  • 2021-01-13 21:47

    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.

    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 case, the "remotes/upstream" one)

    0 讨论(0)
提交回复
热议问题