GitPython nothing appears in working copy after pull

时光怂恿深爱的人放手 提交于 2019-12-07 07:23:26

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()

I don't know how properly resolve this problem but the only idea is as phobic say to reset hard repo after create_head.

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()
repo.head.reset('--hard')

After that all further pulls should work properly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!