How to ignore .gitignore when using git worktree?

Viewed 682

I'm using git worktree to work with my branches.

For example:

git worktree add -b Foo ../Foo origin/master

It creates a new folder, new branch, and new worktree, as expected. However, there is no node_modules/ in the new folder.

My .gitignore contains node_modules.

Is it nice way to create a complete folder?

I can create a perfect folder using a shell script (like cp xxx xxx), but I want to create perfect folder using git worktree.

1 Answers

Of course it doesn't create node_modules/. You told Git to ignore those files; it's effectively unaware that they exist. Why would it create them?

Don't copy those files from your other folder (your package.json and lockfile may be different). Run yarn or npm install in the new directory instead.

Related