4

Lets say I have the following two branches and the local branch is 'mybranch'

master
master\file.txt
master\directory\file2.txt
...

mybranch
mybranch\otherfile.txt

I'd like to create a new directory, call it 'test'. I'd like to put ALL of the contents of master into mybranch\test. I don't want those files and directories staged, just copied.

I've tried git checkout mybranch -- with various combinations of wildcards, slashes, dots, and I just can't get it to work.

So in this example, my end result would be

mybranch
mybranch\otherfile.txt
mybranch\test\file.txt
mybranch\test\directory\file2.txt

Can this be done without switching branches?

Suraj
  • 35,905
  • 47
  • 139
  • 250
  • 1
    Looks like you could do this with `git archive`, see first answer to [this question](http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export). – tcovo Mar 26 '12 at 17:32
  • @tcovo - could you add as answer so I can give you credit? – Suraj Mar 26 '12 at 18:05

1 Answers1

5

As suggested in answer to this question, you can use git archive to retrieve the contents of a commit, and then extract the archive to the desired location:

git archive master | tar -x -C test
Community
  • 1
  • 1
tcovo
  • 7,550
  • 2
  • 20
  • 13