<jupyter_start><jupyter_text>Ignoring Things What if we have files that we do not want Git to track for us, like backup files created by our editor or intermediate files created during data analysis? Let’s create a few dummy files:<jupyter_code>mkdir results
touch a.dat b.dat c.dat results/a.out results/b.out<jupyter_output><empty_output><jupyter_text>and see what Git says:<jupyter_code>git status<jupyter_output><empty_output><jupyter_text>Putting these files under version control would be a waste of disk space. What’s worse, having them all listed could distract us from changes that actually matter, so let’s tell Git to ignore them.We do this by creating a file in the root directory of our project called .gitignore:<jupyter_code>nano .gitignore
cat .gitignore<jupyter_output><empty_output><jupyter_text>These patterns tell Git to ignore any file whose name ends in .dat and everything in the results directory. (If any of these files were already being tracked, Git would continue to track them.)Once we have created this file, the output of git status is much cleaner:<jupyter_code>git status<jupyter_output><empty_output><jupyter_text>The only thing Git notices now is the newly-created .gitignore file. You might think we wouldn’t want to track it, but everyone we’re sharing our repository with will probably want to ignore the same things that we’re ignoring. Let’s add and commit .gitignore:<jupyter_code>git add .gitignore
git commit -m "Ignore data files and the results folder."
git status<jupyter_output><empty_output><jupyter_text>As a bonus, using .gitignore helps us avoid accidentally adding to the repository files that we don’t want to track:<jupyter_code>git add a.dat<jupyter_output><empty_output><jupyter_text>If we really want to override our ignore settings, we can use git add -f to force Git to add something. For example, git add -f a.dat. We can also always see the status of ignored files if we want:<jupyter_code>git status --ignored<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.059470264867566215, 'fraction_numerical': 0.0, 'mean_word_length': 5.7407407407407405, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '345776', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 573, 'n_tokens_neox': 568, 'n_words': 265, 'path': '02-git/05-ignoring_instructor.ipynb', 'repo_name': 'turnpenney/rcsc18_lessons', 'size': '2001'}