Git: save ignored files when switching branches

I know this looks like a duplicate of GIT: how to ignore files when switching branches? but I could not find the answer.

So, I created a new branch with a flag --orphanto delete the commit history. Then I did git rm --cachedin all the files, changed .gitignoreto ignore some of them, and then added and committed. As expected, the ignored files are not in the new repo (nor in any of its history). However, they disappear when I switch branches (that is, when I look at the old branch and then check the new one again). How can i avoid this?

EDIT: The purpose of the whole operation was to prepare the project for publication on GitHub, so I wanted to hide some configuration files containing personal information, such as passwords, keys, etc. So I deleted the commit history by creating a new orphan branch. I understand that probably compiling the files before adding them .gitignoreto would solve the extinction problem, but that would make the files ultimately visible in public history. I tried to do git add -f, then git rm --cached, but that doesn't do the trick.

+4
source share
1 answer

However, they disappear when I switch branches (that is, when I check the old branch and then check the new one again). How can i avoid this?

. . publish , .gitignore. ! , , . , .gitignore .

:

gitignore , Git. , Git, .

, publish, , . .gitignore , , .

( , - - , , . , , .)

, . , BFG Repo Cleaner, . .gitignore , , , GitHub.

+3

All Articles