Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

As noted in this question, I ran into an issue with git add /**.... I can't actually find any documentation on the "/**" form of path specifications - possibly because it's hard to google.

How is it meant to work, exactly? I'm particularly curious that git add /\*\*.py can work but git add /path/foo.py won't - why is the slash allowed at the start of the string with the ** notation?

EDIT more info:

$ echo /**.py

(This version of Bash doesn't support shopt -s globstar)


$ git add /**.py

adds (silently) a file three directories beneath the current directory. Git apparently doesn't do any globbing at all, so I'm really curious what's going on here.

These also work:

`git add '/**.py'`
`git add /*******.py` 

This doesn't:

`git add **.py`

This seems to add all files anywhere in the current working directory.

(Bash 3.2.48 on OSX)

share|improve this question
You need to define "work" here - Please paste the actual commands, the output, and what you expected to happen instead. –  l0b0 May 9 '12 at 14:53
Ok, I pasted the commands above. None of them produce any output. I don't have "what I expected to happen" - that's what I'm asking. The behaviour where it adds no files, and produces no output seems confusing, so I'm asking how these commands are being interpreted. –  Steve Bennett May 11 '12 at 0:49

1 Answer 1

Globs are resolved by the shell when you run such a command, not by git. Try echo /** to see what that resolves to. There is a recursive glob pattern in Bash which uses this syntax, but you have to shopt -s globstar to enable it (it seems to be disabled by default).

git add /\*\*.py tries to add a file called literally **.py. While it's possible to create such a file, it's probably not intended.

git /path/foo.py is meaningless - I assume you meant git add /path/foo.py.

In all these commands, you should remove the initial slash - You generally want to refer to files in a repository by their path relative to $PWD.

echo /**.py will print /**.py unless shopt nullglob is off or you actually have a .py file in the root directory.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.