Search code examples
gitgitignore

How can I prevent developers from pushing a particular file?


I have a repo, used by developers working on my project. In this repo, there is a file ".your_local_variable.php", where there are paths that have to be filled by the developer, relative to their machines, before starting working on the project. I want the developers to pull the "template" of this file only once when they first clone the repo on their machines, but I want to prevent them to send this file on a merge request.

I tried to put it in the .gitignore, and push .gitignore remotely, so they can retrieve it, but the file ".your_local_variable.php" is still showing up on command "git status" as "changes not staged for commit".

Is there any way to prevent pushing this file, and to hide it from git status, while keeping a "template version" of this file on the remote repo?


Solution

  • If the file was already checked into git, just adding it to .gitignore won't resolve the problem.

    You will need to delete the file from git with git rm + add the file to .gitignore, then push this commit - which contains the delete + ignore. Everyone will need to pull this change so that it stops showing up in your git status.

    You can also keep the template version on git, and just tell everyone to copy + rename the file into the one ignored. This is what it should look like on git :

    • template-for-everyone.file (checked into git so people can retrieve, no one should change this file, unless you want to change the template)
    • my-local-template.file (add this file into .gitignore, everyone should copy the template and edit it with this name)
    • .gitignore (which contains my-local-template.file)