How can I tell which remote “parent” branch my branch is based on?

后端 未结 4 1862
温柔的废话
温柔的废话 2021-01-30 10:47

I have a scenario in which there a several remote tracking branches within my local repository that I must sync up to. Our workflow model is:

  • make a branch locally
4条回答
  •  耶瑟儿~
    2021-01-30 11:11

    git branch -vv will:

    • list all your local branches
    • display the name of the remote branch next to each local branch
    • highlight the active local branch

    ...from this you will be able to determine the remote branch of the current active branch, and more besides.

    If you have a lot of local branches, the list may be very long. Use git branch -vv | grep SOMEWORD to limit the output to only branches containing SOMEWORD. If you can think of a word unique to your branch you'll get the best filter (one result only).

    You will also get some additional data in the output, namely the number (SHA1) and message of the last commit. The grep filter will apply to these to. I couldn't find a way to exclude it.

    From the Git branch documentation:

    -v

    -vv

    --verbose

    When in list mode, show sha1 and commit subject line for each head, along with relationship to upstream branch (if any). If given twice, print the name of the upstream branch, as well (see also git remote show ).

    (Based on your comment, yes, it seems that the 'correct' question would ask about the "remote" branch rather than the "parent" branch. But that's what I searched for too! :) )

提交回复
热议问题