3

I'm trying GitHub pages with a webpack project, so I made a new branch (forgot to use --orphan) and keep different files in them.

  • On master branch, dist/ directory is .gitignored.
  • On gh-pages branch, all files are ignored except for dist/, index.html and some other files.

When I npm run build on master, the new dist/ is built, but it is overwritten by the former dist/ when I checkout gh-pages. How to keep them and make it possible to add and commit them after?

InQβ
  • 518
  • 4
  • 22
  • 1
    Use two separate worktrees. Or even a submodule, but that's not necessarily required. – o11c Aug 29 '17 at 03:44

2 Answers2

1

Regarding the possibility of using two separate worktrees, you can use the git worktree command: that avoids having to maintain two different clones.

Don't forget also "Simpler GitHub Pages publishing": you can maintain your pages in the same branch as the rest of your repo, in a docs/ sub-folder.
That way, you don't need to switch branches at all.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • What if your gh-pages isn't a doc of your app, but a demo? Can you tell Github to look to the `dist` directory instead of `docs`? – ESR Aug 30 '17 at 02:02
  • @EdmundReed in that case, you can use gh-branch instead, and declare (in the master) branch dist/ as a submodule (whose url is your gh-branch repo URL!) See https://stackoverflow.com/a/40967706/6309. That way, you have both content available in the same worktree. – VonC Aug 30 '17 at 06:52
0

Despite the better practice here, I have found a way to do the file transferring directly.

  1. On master branch, after committing everything and doing the build;
  2. git add --force dist/
  3. git stash
  4. git checkout gh-pages
  5. git stash apply
  6. Unstage .gitignore in case it is also transferred
  7. Solve the conflict

However, it requires too many steps to be useful, and maybe simply cp them would be much easier.

InQβ
  • 518
  • 4
  • 22