Skip to content

Repo.heads only shows the master branch #1079

Description

@mengjade

I used GitHub Desktop to clone a repo with two branches from URL.
The following scripts only print the master branch.

repoRepo = git.Repo(os.getcwd())
print(repoRepo.heads)

If I switch to the other branch using GitHub Desktop, then it returns two heads. If I switch back to master again, it also shows two heads.
image

Is there a way to show all the heads at the beginning to avoid this manual work? For example, if I have 10 branches, i don't want to manually switch the branches 10 times to get them into Repo.heads.

Thanks.

Activity

  1. Byron commented on Nov 8, 2020

    @Byron
    Member

    I believe what's at display here is a 'smart' feature implemented specifically to list local branches as well as remote branches. This explains why GitPython sees these as heads only after they have been checked out once, after all, this would create a local tracking branch.

    In order to emulate this feature, one would have to look at remote branches as well.
    I am closing this issue as Q&A, please feel free to keep posting here with follow ups as you see fit.

  2. reopened this on Feb 26, 2021
  3. locked and limited conversation to collaborators on Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions