Search code examples
c++cgitversion-controllibgit2

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.


Solution

  • 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.