Skip to content

repo.index.add('.') adds .git directory #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
marcwebbie opened this issue Jun 2, 2015 · 6 comments
Closed

repo.index.add('.') adds .git directory #292

marcwebbie opened this issue Jun 2, 2015 · 6 comments
Assignees

Comments

@marcwebbie
Copy link

When I perform repo.index.add('.') gitpython adds .git directory...

The question is how can I add all changed files to stage without including the .gitdir?

Thanks for this great project. :)

@Byron Byron self-assigned this Jun 2, 2015
@Byron
Copy link
Member

Byron commented Jun 2, 2015

I think the easiest would be to call the git command directly, such as in:

import git
r = git.Repo()
r.git.add(u=True)

Of course this functionality could also be emulated using pure-python, but unless you want to do special processing, I don't think it's worth the effort, both for the developer or for the CPU.

To answer your question, repo.index.add(...) is low-level enough to unconditionally add all paths given in the items iterable, and therefore it is not suited to emulate something like git add -u.

In future, you might consider using stackoverflow along with the GitPython tag as it usually yields better answers, faster.

Please close this issue if your problem is solved.

@Byron
Copy link
Member

Byron commented Jun 2, 2015

You can watch the development stream on youtube.

GitPython #3 [answer issue 292 - using git add -u]

thumb

@marcwebbie
Copy link
Author

Yes, it solves for me, repo.git.add(u=True) or repo.git.add('--all')

Great video by the way. ;)

@Dreamsorcerer
Copy link

Just a note for anyone else who stumbles onto this and might make the same mistake.

repo.git.add(u=True) is not the same as git add . as it does not add untracked files. Use repo.git.add(A=True) instead.

@mitar
Copy link

mitar commented Dec 4, 2019

I find repo.git.add(all=True) the nicest.

@vazanth-r
Copy link

Thanks @Byron This was really helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants