2

Let's say I have a master branch and a gh-pages branch. The directory structure for master looks like this:

projects/
    project-one/
        src/
            app.js
        dist/
            bundle.js
            index.html
    project-two/
        src/
            app.js
        dist/
            bundle.js
            index.html

The directory structure for gh-pages is blank, but I want it to look like this:

project-one/
    bundle.js
    index.html
project-two/
   bundle.js
   index.html

I've tried instructions detailed here

$ git checkout master
$ git checkout gh-pages project-one/dist
error
$ git checkout gh-pages -- project-one/dist 
error

That should copy the dist folder into the gh-pages branch but I get a error pathspec: file not found error so I tried git pull to sync to the remote, but this does not solve the problem.

Note that in order to make gh-pages clean I used git rm -r on the whole directory because I do not want gh-pages directory structure to be inherited from master.

How can I copy everything in each project/dist folder from the master branch into the gh-pages branch?

edit: tried git checkout gh-pages project-one/dist/** which gave me a better error msg: error: pathspec 'dist/bundle.js' did not match any file(s) known to git.

Community
  • 1
  • 1
Daniel Lizik
  • 3,058
  • 2
  • 20
  • 42

1 Answers1

2

You're doing it backwards. You need to be in the scope of the gh-pages branch and then do your checkout operations:

$ git checkout gh-pages
$ git checkout master dir/file1

I believe the only way you could copy from a branch to another branch and change directory (without of course doing the manual work after the copy) would be the following:

$ git show master:dir/file1 > new_location/file1
Thomas Stringer
  • 5,682
  • 3
  • 24
  • 40
  • Ok thanks, now I know how to copy the files successfully, but the directory structure is still being copied. What if I want to copy and move all files in `dir/**` to the root folder of `gh-pages`? With `$ git checkout master dir/**` the `dir` folder is also being copied into `gh-pages`. – Daniel Lizik Sep 04 '15 at 19:51
  • @Daniel_L perhaps just do a `$ git mv` after the `checkout` operation? I'm not sure if there's a one-command for this. – Thomas Stringer Sep 04 '15 at 20:06