Ignore git files locally but do not remove them from the repository

My team has is working on a git repository which contains a fully deployable WordPress app. This was configured in this way so that it could be deployed to a AWS stack quite easily. The repository contains a caching plugin which creates two folders in the wp-content/ folder named

cache/
w3tc-config/

When devs are checking out this application they are removing the caching features for development and thus the plugin is writing these changes to the two directories it uses. Which then encourages .git to stage them for a commit.

Read More

Is there anyway we can ignore these folders on dev machines but not remove them from the repo? Also i’d be interested in hearing other solutions which might help me get round this problem even if it is a larger change.

Related posts

Leave a Reply

3 comments

  1. If you check out your repository and let master follow that, then you can create a devel branch where you just add cache w3tc-config to .gitignore.

    I do something similar at work where I use git-svn to work with a svn repository which “links” in another svn repository for a sub module. Git clone did not fetch that sub module, so I just copied in the content from a svn checkout, checked into a devel branch (leaving master following the svn trunk branch), and added the sub module directory to .gitignore.

    This is a solution that will require specific action from each developer, and not something you can push out from the repository. But similar to git hooks, if you create a tools/do_it.sh script that does the required actions it is possible to lower the bar considerably.

  2. You cannot have it both ways. Either the files are tracked or they are not. You cannot keep files in the repository but avoid tracking changes to them. Once they are tracked, it is up to you to not git add them. (And it is worth noting that git does not track folders ever.)

    Create an archive called UnzipMeRightAfterCloning.zip that contains all the stuff you want ignored. Anyone cloning the repo needs to extract that archive, and it will add all the files/folders blocked by your .gitignore settings. (And given your current setup, you will have to untrack the files in those folders first.)

    Put these in your .gitignore file. (Do not put in asterisk.)

    cache/
    w3tc-config/
    
  3. Yes, create a local .gitignore file in the project directory.
    in the file paste the following

    cache/*
    w3tc-config/*
    

    Now, these files will be excluded from git, but they won’t be removed from the repository.