Git: copy all files in a directory from another branch

alexenko picture alexenko · Apr 19, 2010 · Viewed 98.4k times · Source

How do I copy all files in a directory from another branch? I can list all of the files in that directory by doing

git ls-tree master:dirname

I can then copy all of the files individually by doing

git checkout master -- dirname/filename

However, using wildcards has so far been a total fail. This does nothing:

git checkout master -- dirname/*.png

Though I guess I can use a bash script to do that, there has to be an easier way, right?

Answer

CB Bailey picture CB Bailey · Apr 19, 2010

As you are not trying to move the files around in the tree, you should be able to just checkout the directory:

git checkout master -- dirname