Using two asterisks to add a file in git

Viewed 16935

I want to add a file which has a unique file name but a long preceding path (e.g. a/b/c/d/filename.java). Normally I would add this to my repository by doing

git add *filename.java.

However I have also done this before:

git add a/b/c/d/filename*

So I tried to combine the two:

git add *filename*

but this does something weird. It adds every untracked file. I can see possible reasons for failure but they all should occur in one of the previous two commands so I don't know why this is happening.

My question isn't so much about how to add a file to a git repository with just its file name (although that would be useful). My question is what is my misunderstanding of the * operation which makes me think the above should work.

Info:

I am using Git Bash for Windows, which is based on minGW.

2 Answers

You could try with git add ./**/*.java

Note: I tested with zsh, it should also work for bash as well.

Related