Search code examples
pythongitgitpython

GitPython nothing appears in working copy after pull


I'm new in PythonGit and I have problem with pulling and pushing. I created locally bare repo and pushed to it an initial commit. After that I tried to init new user repo using PythonGit, fetch it and pull from it. I have no problem with initialize the repo however I can't get anything from remote/bare repo. My code:

import git

repo = git.Repo.init('.')
origin = repo.create_remote('origin', '/home/paweber/git/my-repo.git')
origin.fetch()            
repo.create_head('master', origin.refs.master).set_tracking_branch(origin.refs.master)
origin.pull()

In ipython console for fetch and pull I get:

In [5]: origin.fetch()
Out[5]: [<git.remote.FetchInfo at 0x7f4a4d6ee630>]

for fetch and

In [6]: origin.pull()
Out[6]: [<git.remote.FetchInfo at 0x7f4a4d6e6ee8>]

for pull. After pull action, nothing is pulled at all and repo is still empty but exists. What I'm doing wrong?


Solution

  • pull() doesn't do anything as master is already at its destination commit, the one pointed to by origin/master.

    This code will work as expected:

    import git
    
    repo = git.Repo.init('.')
    origin = repo.create_remote('origin', '/home/paweber/git/my-repo.git')
    origin.fetch()
    # the HEAD ref usually points to master, which is 'yet to be born'            
    repo.head.ref.set_tracking_branch(origin.refs.master)
    origin.pull()