Search code examples
gitversion-controlmsysgit

Git ignore particular files


I've been playing around with it for a while and I like it very much. Let me describe my case.

I have two computers where I have my repositories and a remote repository.

in my files I have one configuration file which differs on both computers. so when I do pull on my computers I don't need that config file to be pulled, but everything else. How can I achieve that?

I've read about .gitignore files but I can't figure out how they work or are they the thing that I need in my case.


Solution

  • .gitignore is for files/folders that you haven't checked in already. It's essentially a text file that you create in the repository and has a list of paths relative to the directory it was placed in, which Git will ignore. You can check-in the .gitignore file as part of the repository. you can find examples - at the end of this page

    However if your file has already been checked in the repository then you can use:

    git update-index --assume-unchanged file
    

    which will tell Git to ignore any changes to that file made in the future. However this is a local configuration so you will have to do it on each machine you check out. You can revert it by doing:

    git update-index --no-assume-unchanged file
    

    Depending on what configuration that file contains it might be a good practice to have a skeleton/example config file in the repository - similar to what PHP guys do with config_example.php, which then is used by people to create config.php, which in turn never get's checked in the repository because it is ignored.