How to add modified, deleted, untracked to a Git repository in GitPython

10.4k views Asked by At

I thought somehow update=True will add all modified, deleted and untracked files to the index. I am not sure what the way is. Can someone help me here?

repo = Repo(working_repository_url)
repo.git.add(update=True)
repo.index.commit(my_msg)

I mean. I can certainly get the :

untracked_items = repo.untracked_files

and this is only for the untracked files. I want to add untracked files, deleted, modified files to the index and then do a commit to all.

More likely I am looking something that is equivalent to git add --all

3

There are 3 answers

0
phd On

Try

repo.git.add(all=True)

It's one-to-one correspondence for git add --all

2
oqqA.vw On

Don't use repo.index.add(), only repo.git.add()

repo.git.add('-A')
1
valcapp On

To keep using repo.index:

repo.index.add('**')