gitgit-pull

.ENV Updated When Git Pull


I tried git pull to our server, with this command

git pull origin v2.0

When it succeeds, the .env file on the server is also replaced. Even though I have registered .env in .gitignore.

.env
.env.example
.env.prod
node_modules

Has anyone experienced something similar? I'm afraid I'm doing something wrong.

I want .env to not change on the server when I do a git pull


Solution

  • Where did you get the idea .gitignore would do that? Genuine question, you're not accountable to anyone here for it but you should find out the answer yourself and stop trusting whatever source you got it from as any source of accurate information.

    git help ignore gets you

    A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details.

    Mark the path --skip-worktree in the index instead, git update-index --skip-worktree .env, that's the "don't touch, don't even look at this file" bit. Git's not built to be a deployment server, people can easily finagle it into working in simple cases like this, so long as they really stay this simple, but even here the index entry goes and the flag you set go away if you ever check out a commit that doesn't have that file, you're better off moving the tracked file out of the way.