1

I have certain files that I need to have different on a staging server from a clients repo. One for example is the .htaccess file.

I don't want locally modified files to be tracked so I added it to .git/info/exclude

I then ran git update-index --assume-unchanged .htaccess (I also tried --skip-worktree)

But now when I try to switch branch git checkout myotherbranch I get this message:

error: Your local changes to the following files would be overwritten by checkout: .htaccess Please commit your changes or stash them before you switch branches. Aborting

But because I am ignoring the file I can't stash it.

I actually have many files locally ignored, I just have just shortened example to one file for simplicity.

I think the issue is that the branch I am switching into has a different .htaccess file version than my current branch.

Is there any way to switch into this branch while having the file locally ignored?

Edit for close vote: please read my question. removing the file from repository is not the answer. i am locally ignoring file so it is independant of main repo. This would effect main repo. I only want it excluded locally and to have ability to change branches.

Guerrilla
  • 13,375
  • 31
  • 109
  • 210
  • Possible duplicate of [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – phd Oct 10 '18 at 15:28
  • @phd No that is not same issue at all. – Guerrilla Oct 10 '18 at 15:29
  • You can't "locally ignore" a file (listing in `.git/info/exclude` does not actually do that: the file is either tracked or untracked, and exclude or ignore affects only *untracked* files). For what you are actually doing, and what you must do to work with that, see https://stackoverflow.com/q/52703026/1256452 – torek Oct 10 '18 at 18:06

2 Answers2

1

If you want those files been ignored you should use the .gitignore file, the problem is that if you have those files already tracked on your git history you need to make git forget them with:

git rm --cached <file>
Javier Menéndez Rizo
  • 2,138
  • 3
  • 12
  • 22
0

You likely identified the issue, there is already an .htaccess in the other branch.

Git needs to know about the changes:

git update-index --no-assume-unchanged .htaccess 

Stash those changes:

git stash save "Save local conf"

You can now checkout in your other branch:

git checkout myotherbranch

Finally, you can restore your local changes:

git stash pop

Last thing, I'd use --skip-worktree to protect the file. Why? See here

saccodd
  • 972
  • 9
  • 23