I have a repo test-repo
, it contains two branches master
and dev
. Any files / directories that are in the master
branch's .gitignore
files appear locally in both branches when I git checkout
to them, I assume this is normal behaviour as those files aren't being tracked by Git so they're just in the test-repo
directory no matter what. I don't want this to happen. My ideal setup is like below:
When I git checkout master
the local file / directory structure should be like so:
test-repo/
.gitignore (this file just contains `should-be-ignored.md`)
should-be-ignored.md
should-only-show-in-master.md
When I git checkout dev
the local file / directory structure should be like so:
test-repo/
should-only-show-in-dev.md
If anyone has any idea on how to achieve this setup I'd really appreciate it.
The real-world version: I'm working on GitHub, when you add a branch of gh-pages
it acts as free static web hosting essentially. I have a repo which contains my front-end web build boilerplate, the master
branch contains all the code and the gh-pages
branch would include some examples of what the code does etc. When I'm working on the boilerplate locally I run Grunt (a task runner) which to run properly needs the command npm install
which installs any dependencies, this creates a directory of node_modules
in the root of repo, I don't want this to show on the remote repo so I put that directory in the .gitignore
file. So in my dev
branch (locally) this directory still shows up, what if I wanted separate Grunt tasks for the files in the dev
branch? This would mean I'd need another node_modules
directory in that branch, which can't be done since the one from the master
branch is always in that local directory no matter what. Do you see my problem now?
With the additional context you have provided regarding gh-pages (thought I am bit confused about master and dev branches coming in to the picture):
The gh-pages branch is essentially a separate repo and serves a different purpose (usually documentation.)
What I generally do is to not keep checking out between by code branch and gh-pages branch. I just clone the repo two times and have one for normal development, and the other for gh-pages stuff. Keeps it simple, and the two are treated as two repos, as they should be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With