I have copied the repository from remote GitHub and now going into that git repository in local machine where repository downloaded.

below am issuing command to fetch the branch name, but its not working

$ git branch --contains v0.3

From git man:

--contains [<commit>]

Only list branches which contain the specified commit (HEAD if not specified). Implies --list.


With --contains, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the named commit).

Just use

git branch

which should show all the local branches of your repo. The starred branch is your current branch.

If you want to retrieve only the name of the branch you are on, you can do:

git branch | grep \* | cut -d ' ' -f2
  • 1
    git branch --show-current would be safer as your grep may find branches with * in their names. However, this does not get the branch name associated with a particular tag, which was what was asked for. – Kusalananda Aug 15 at 6:35

git branch without -a only shows local branches.

You probably want git branch -a --contains v0.3 to see all branches from github that contain the given tag. But this may be less helpful than you think - it will list the branch the tag was originally made on as well as any branches spawned off that since the tag.

  • Thanks i also explored with -a option and it worked .. as the tag is unique for me its working – Anand Aug 16 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.