Skip to content

how to access remote upstream master branch tree #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
greenpau opened this issue Dec 22, 2015 · 3 comments
Closed

how to access remote upstream master branch tree #373

greenpau opened this issue Dec 22, 2015 · 3 comments

Comments

@greenpau
Copy link

How do I access remote upstream branch tree?

local_active_branch_tree = self.repo.heads[str(self.repo.active_branch)].commit.tree;
local_master_branch_tree = self.repo.heads.master.commit.tree;
remote_upstream_master_branch_tree = ???

the doc are silent about it. http://gitpython.readthedocs.org/en/stable/reference.html#module-git.remote

class git.remote.FetchInfo(ref, flags, note='', old_commit=None, remote_ref_path=None)
@Byron
Copy link
Member

Byron commented Dec 26, 2015

For questions, please consider using stackoverflow instead, suitable answers are more likely there and will be made much faster. Just be sure to set the gitpython tag.

However, to answer your question explicitly, I believe that tracking_branch() would be what you are looking for.

import git
repo = git.Repo()

local_active_branch_tree = repo.active_branch.commit.tree
local_master_branch_tree = repo.heads.master.commit.tree
remote_upstream_master_branch_tree = repo.heads.master.tracking_branch().commit_tree

@Byron Byron closed this as completed Dec 26, 2015
@greenpau
Copy link
Author

greenpau commented Jan 7, 2016

@Byron , thank you for the answer!

quick correction to the above:

remote_upstream_master_branch_tree = repo.heads.master.tracking_branch().commit.tree

@Abbyyan
Copy link

Abbyyan commented Nov 25, 2019

Thanks a lot. To get the remote branch of each local branch , It works.

heads = repo.heads
for head in repo.heads:
     if str(getattr(repo.heads,str(head)).tracking_branch()) == "origin/master":
          print("yes")
     print(head," ",str(head),"  ",getattr(repo.heads,str(head)).tracking_branch())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants