Thursday, February 28, 2019

Untracking files in git

In one of my current projects, pyblueprint-py3, I have a config file.  This file gets edited locally after cloning the repository, and those changes get seen by git.  That is a problem.  This is a file that is distributed with default values that the user edits, and git does not need to know about these changes.  But, how do we tell git not to care about changes to a file?  Good question, and here is the answer.

For your config file (or whatever file it is that you want to prevent git from tracking), create it in your repository, and then issue the following command:

    git update-index --skip-worktree file_name

The file_name should include the path if it isn't in the current directory (ie: its in a subdirectory).

If the file that you don't want to track is already on git's radar, then you can do the following:

    git rm 
    git rm -r --cached 
    git commit -m'- Cleaning up and removing file to be ignored'
    git push

Then, add the file and edit the conf file with the generic placeholder and do this:

    git add 
    git update-index --skip-worktree 
    git commit -m'- Committing new, untracked file'
    git push

One thing to remember, is that when someone clones your repository, before they do anything, they will need to reissue the 'git update-index' command above for the specific file you untracked.  That should be noted in your documentation.



No comments:

 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.