pulling and integrating remote changes with pygit2

I do have the following problem. I’m writing a script which searches a folder for repositories, looks up the remotes on the net and pulls all new data into the repository, notifying me about new changes. The main idea is clear. I’m using python 2.7 on Windows 7 x64, using pygit2 to access the git features. The command-line supports the simple command “git pull ‘origin'”, but the git api is more complicated and I don’t see the way. Okay, I came that far:
import pygit2
orepository=pygit2.Repository("path/to/repository/.git")
oremote=repo.remotes[0]
result=oremote.fetch()

This code retrieves the new objects and downloads it into the repository, but doesn’t update the master branch or check the new data out. By inspecting the repository with TortoiseGit I see that nothing way checked out , even the new log messages don’t appear when showing the log. I need to use the git pull command to refresh the repository and working copy at all. Now my question: What do I need to do to do all that by using pygit2? I mean, I download the changes by fetching them, but what do I need to do then? I want to update the master branch and working copy too…
Thank you in advance for helping me with my problem.
Best Regards.

  • FETCH_HEAD reference not updating correctly after “git fetch”
  • Git: What do the numbers reported by `git fetch` mean?
  • “git push” doing the same as “git fetch” from the remote
  • git refusing to fetch into current branch
  • git fetch not update my local repository
  • What is the difference between these `git fetch` syntaxes?
  • Writing long commit messages in git?
  • Create Git patches for two files across several renames
  • How to make 'git log --oneline' show which commit messages are multiline
  • How to automatically generate commit message
  • Change a branch name in a Git repo
  • Can I import from SVN to Git without connecting to a remote server?
  • One Solution collect form web for “pulling and integrating remote changes with pygit2”

    Remote.fetch() does not update the files in the workdir because that’s very far from its job. If you want to update the current branch and checkout those files, you need to also perform those steps, via Repository.create_reference() or Reference.target= depending on what data you have at the time, and then e.g. Repository.checkout_head() if you did decide to update.

    git-pull is a script that performs very many different steps depending on the configuration and flags passed. When you’re writing a tool to simulate it over multiple repositories, you need to figure out what it is that you want to do, rather than hoping everything is set up just so that git-pull won’t surprise you.

    Git Baby is a git and github fan, let's start git clone.