'Copying content of a directory on another branch

I have 2 branches on github:

  • master
  • gh-pages

My branch master has the directory _site which contains all the files that I need to be stored on the root of gh-pages.

I am using the git command: git checkout master -- _site

To copy the contents of _site to the gh-pages branch.

My issue is that I am getting the directory and it's content while I need the content only on the root.

Is this possible?



Solution 1:[1]

One option is to set gh-pages as submodule of your own repository.

That means adding thegh-pages branch content as a subfolder of your current repository, in the master branch, using git submodule.
(unless, as explained here, you chose the master branch itself as source for GitHub Pages)

git checkout master
git submodule add -b gh-pages -- /remote/url/of/your/own/repo gh-pages
git commit -m "Add gh-pages branch as submodule"
git push

You will have a gh-pages subfolder, that you can update at any time with:

git submodule update --remote

My issue is that I am getting the directory and it's content while I need the content only on the root.

You would generate, from your main repository, the site content not in the directory _site, but in the directory gh-pages (which would thereforce have directly the site content).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC