How do I determine what branch/tag I have checked out in git?

前端 未结 4 1965
感动是毒
感动是毒 2021-01-14 12:01

I clone my source using git clone https://gerrit.wikimedia.org/r/p/mediawiki/core.git w/. Then I specify a specific branch/tag by doing git checkout

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-14 12:36

    How do I determine what branch/tag I am on?

    First, since Git 2.22 (Q2 2019), you have git branch --show-current which directly shows you your current checked out branch.

    Second, it won't show anything if you are in a checked out worktree (created with git worktree add)

    For that, check Git 2.23 (Q3 2019), with its "git branch --list" which learned to show branches that are checked out in other worktrees connected to the same repository prefixed with '+', similar to the way the currently checked out branch is shown with '*' in front.

    Example:

    See commit 6e93814, commit ab31381, commit 2582083 (29 Apr 2019) by Nickolai Belakovski (``).
    (Merged by Junio C Hamano -- gitster -- in commit 99eea64, 09 Jul 2019)

    branch: add worktree info on verbose output

    To display worktree path for refs checked out in a linked worktree

    The git branch documentation now states:

    The current branch will be highlighted in green and marked with an asterisk.
    Any branches checked out in linked worktrees will be highlighted in cyan and marked with a plus sign.

提交回复
热议问题