1

Problem

I would like to have one 'wwwroot' repo for my iis server, with different branches tracking different 'sites', specifically a production site (wwwroot/prod), a dev site (wwwroot/dev) and perhaps some other sites (wwwroot/other).

I assumed it would be trivial to simply have each branch track only it's respective folder, ignoring the other subfolders. This "works", except switching between branches deletes the other branches.

I've tried simple .gitignores that ignore the other directories by name, and more complex .gitignores that ignore everything but the respective directory.

I'm not worried about .gitignore file merge conflicts if/when I decide to merge branches.

I imagine I could use the solution posed elsewhere on SO using different excludes and updating the symlink on branch change, but I don't think that's ideal for long-term/anyone who replaces me. Surely I'm just using .gitignore wrong?


Example

wwwroot/prod   (tracked by prod branch, ignores dev and other)
wwwroot/dev    (tracked by dev branch, ignores prod and other)
wwwroot/other  (tracked by other branch, ignores prod and dev)

but for example, after setting up the gitignores, changing to a different branch causes the other (previously checked out) branch to be removed from wwwroot working directory (and thus the web pages are no longer accessible)

goofology
  • 914
  • 2
  • 10
  • 21
  • You can't (quite) get what you want, because files that are in a commit are ... in a commit. See [this answer](https://stackoverflow.com/a/63331727/1256452) for details (and what you *can* do). – torek Aug 11 '20 at 19:29
  • Thank you - "you are telling Git: Remove everything related to the current commit and switch to the other commit." - guess the answer is rather obvious. – goofology Aug 11 '20 at 19:59

1 Answers1

1

If you can afford to not track wwwroot content (meaning that folder or series of folders does not need to be tracked in Git, in commits, but can remain private), then I would:

  • create those folders outside your repo
  • track symlinks

That is

  • wwwroot -> /../prod (prod is a folder in the same parent folder than the repo itself)
  • wwwroot -> /../dev (dev is a folder in the same parent folder than the repo itself)
  • wwwroot -> /../other (other is a folder in the same parent folder than the repo itself)

That way, you only track wwwroot, which changes depending on the branch, and symlink to the right external folder, using a relative path.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250