Implementing "git pull" with libgit2?

I have a relatively short Gist that libgit2 should use to emulate the functionality of the git pull command. Unfortunately, it does not quite work.

In short, snippet:

According to git_remote_stats() , objects are actually retrieved. But the working directory does not change to reflect the latest commit. I tried to add:

 git_checkout_head(repo, NULL); 

... but it didnโ€™t matter.

Input:

  git checkout master 

... the terminal displays the following output:

  Already on 'master'
 Your branch is behind 'origin / master' by 1 commit, and can be fast-forwarded. 

How to fast forward?

+6
source share
1 answer

You must run git pull origin master

or

git fetch origin + git merge origin/master

Then you need the libgit2 equivalent merge function.

Merge function available in libgit2 v0.20

+3
source

All Articles