Get unpushed commits with libgit2


Is there a way to show all unpushed commits from all available branches with libgit 2. My idea was to use git_revparse(&spec, repo, “origin/master..master”); but this gives me a git_revspec and I don’t know how to use this to iterate over all commits. Another problem is that this method is for a specific branch only.


Use the git_branch_iterator functions to get all of the local branches and git_branch_upstream to get their corresponding upstream branch. Then use the git_revwalk functions to walk over all of the commits that are different between them. Push the upstream with git_revwalk_push_ref and hide the local branch with git_revwalk_hide_ref.

Answered By – Jason Haslam

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published