InQβ
InQβ

Reputation: 521

How to keep ignored files when switching to branch not ignoring them?

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.

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?

Upvotes: 3

Views: 201

Answers (2)

InQβ
InQβ

Reputation: 521

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.

Upvotes: 0

VonC
VonC

Reputation: 1324935

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.

Upvotes: 1

Related Questions