What I would like to do is to checkout a single file or a set of files with a common name part like this
git checkout myBranch */myFile.md
and
<
Git does deal with wildcards, using fnmatch(3). See the pathspec entry in Git glossary.
But to be sure that git can see the wildcards, they must be escaped otherwise your shell will expand them first. Typically, I use wildcards between single-quotes:
git checkout myBranch -- '*/myFile.md'
The wildcards are applied to the whole name, directories included.
As you can see in the documentation, the pathspec also allows magic signature which change how to interpret the pathspec. For example, you can have case-insensitive paths with icase (you can type ':(icase)*readme*'
to find all your readme's).
I quote @bambams's comment here, in case you have problems in Windows:
This is not working for me in Windows with 2.8.1.windows.1 and I'm utilizing Git from the cmd.exe shell so no globbing built in. There is however a solution if you're in such a sorry state. Combine
git diff --name-only
andxargs
to achieve your goal:git diff --name-only
-- ... | xargs git checkout