If I clone a repo and subsequently add one of the downloaded files to .gitignore, I understand I will have to "untrack" them so the .gitignore rules will apply. After untracking them, and are therefore gitignored, are they re-tracked when pulling any updates to those file from the remote repo again?
2 Answers
If the file is still tracked and not ignored in the remote repo, YES. When pulling, it will update the changes to that file. If the file is modified in your local machine, it will raise a conflict.
Actually when you untrack a file, you must push the changes to remote repo, so that the file will be untracked in remote repo as well. If you want to untrack a file only in your local machine there are other ways. Refer: https://stackoverflow.com/a/11209188/1365319
You can also share your ".gitignore" file with your colleges by committing it to the repo, so that they don't accidentally add the file to repo.

- 1
- 1

- 33,556
- 3
- 33
- 43
-
Will this also hold true for excluded files? Might actually be useful to say "ignore all my changes to this file, but if someone else updates it I want to get those changes (or at least get a merge conflict)." – danShumway Jul 16 '15 at 23:18
The .gitignore
entry will tell the repo not to consider tracking new files. If the file had previously been added to the index and has been tracked, it will continue to be tracked until you remove it from the index. That is, .gitignore
will keep the repo from seeing new files. You still would need to do git rm --cached <file>
to remove the existing tracked item. From that point on, it won't be considered.
Note that editing the .gitignore will affect the entire repo. When you commit and push, the remote repo will then be ignoring and untracking.
If your goal is to only ignore locally and not affect the remote, consider this other SO question:
Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user's workflow) should go into the $GIT_DIR/info/exclude file.
-
Thanks Justin. So any git-ignored files will be downloaded into my workspace when fetching any updates, but won't show up under "git status", correct? But what happens if I modify those git-ignored files prior to fetching any updates from the remote? Will it complain about a conflict? – Phillip Jun 28 '12 at 17:23
-
Well no. If you `.gitignore`, then it will have to make its way back up to the remote, meaning that the remote will stop tracking it as well and it will no longer be part of the index. I believe if you use the local approach, when you pull updates your local repo will exclude matches for you. – jdi Jun 28 '12 at 17:26