Edited Answer
You did a git rm --cached -r config.php
, but didn't commit that change.
Next you did git reset config.php
, which cleared the effect of git rm
you had done previously. So you are right now back to where you started from.
Then, you added config.php
to .gitignore
. That won't have any affect since the config.php
is still tracked right now.
Finally, you did a git update-index --assume-unchanged config.php
due to which any changes are not visible locally if you do a git status
/ git diff
. These steps give the illusion that git rm
and .gitignore
worked fine when they didn't.
Instead, do this (the -r
flag was redundant, this is not a directory)
git rm --cached config.php
echo config.php >> .gitignore && git add .gitignore
git commit -m "removing config.php"
Original Answer
But: If I stash the working directory for example to switch the branch, than config.php is restored from the local repos.
Well, You just removed config.php from the current branch ( lets call it master
), but the another branch other
is still tracking it. So that's why you see it. Its got nothing to do with git stash
.
You should probably merge the branch master
into other
to bring the commit into the branch other
.