Join the community!
Visit our GitHub or LinkedIn page to join the Tilburg Science Hub community, or check out our contributors' Hall of Fame!
Want to change something or add new content? Click the Contribute button!
Overview
In this building block, you will learn how to exclude files and directories from versioning, optimizing your Git/GitHub workflow.
By default, Git/GitHub tracks all files you create. However, there are instances where you want to exclude specific files, such as:
- Large data files unfit for GitHub uploads
- Automatically generated code files (that hence do not need to be versioned)
- Sensitive passwords inadvertently stored in your code
The file and directory exclusion technique
Luckily, Git offers a convenient way to exclude files and directories from versioning. Here’s how you do it:
-
Create a new file in your project’s root directory, and call it
.gitignore
(remember the initial.
) -
Open
.gitignore
and specify the files or directories to exclude. For instance,**/DIRNAME
excludes any directory calledDIRNAME
, while*pdf
excludes all PDF files. -
Save
.gitignore
and rungit status
in your repository - the excluded files and directories won’t show up anymore!
Example
For inspiration, explore some example .gitignore
files, or copy-paste the following to your own .gitignore
:
**/rbin/
**/raw/
*RData
*pdf
**/audit
**/input
**/output
**/temp
**/zip
*csv
*xlsx
*~*
*log
*.Rhistory
**/exports
**.ipynb_checkpoints
**__pycache__
*.log
slides/*.gz
slides/*.snm
slides/*.toc
slides/*.nav
slides/*.out
slides/*.aux
.RProfile
Effortlessly enhance your version control by employing this file and directory exclusion technique: create a .gitignore
file in which you specify the directories and files you would like to be excluded from versioning.