git checkout -f in python

1k views Asked by At

I want to make a checkout on a version of a Git repository in Python. I am using the following code lines:

from git import Git
g = Git(os.getcwd())
g.checkout(row[2])

the question is how can I make a forced checkout?

2

There are 2 answers

0
Jamey Hicks On BEST ANSWER

From the documentation, the checkout method takes keyword arguments:

g.checkout(row[2], force=True)

Should do what you want.

1
John Smith On

According to reference checkout function takes first optional argument force=False checkout(force=False, **kwargs)

Therefore, you can just simply call it with first argument force=True, to force the force checkout, like this

g.checkout(force=True, row[2])