Amine Barrak
Amine Barrak

Reputation: 139

git checkout -f in python

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?

Upvotes: 0

Views: 1210

Answers (2)

Jamey Hicks
Jamey Hicks

Reputation: 2370

From the documentation, the checkout method takes keyword arguments:

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

Should do what you want.

Upvotes: 1

John Smith
John Smith

Reputation: 160

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

Upvotes: 0

Related Questions