-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path2.1-gitignore.qmd
73 lines (52 loc) · 2.29 KB
/
2.1-gitignore.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
title: "Intro to `git`"
subtitle: "Block 2.1: Ignoring things: `.gitignore`"
---
## Ignoring files via `.gitignore` 🙈
- By default, git will track *all* the files in your repository.
- If you want it to ignore certain files or filetypes, you have to tell it so explicitly.
- You can do this by using a file called `.gitignore`
- Every file will be compared against the list in `.gitignore` and if it matches, git will ignore the file
- The `.gitignore` file *itself* is tracked just like any other file
## `.gitignore`: classic examples
Ignore every file called myfile.pdf
```bash
myfile.pdf
```
Ignore the file called myfile.pdf in the folder reports at the root of your *repository*
```bash
/reports/myfile.pdf
```
Ignore all PDF files
```bash
*.pdf
```
:::{.callout-tip}
The .gitignore uses the same kind of pattern matching as `git add` (or other git commands)
:::
## `.gitignore`: global vs. local 🫥
- There can be multiple different `.gitignore` files at different levels
- There's one *global* `.gitignore`, that will work across your whole computer
- There are local gitignore files within your repositories
- You can even have a gitignore file in a directory within your repository and it will apply only within that directory
- You can find a list of very useful templates for local`.gitignore` files at <https://github.com/github/gitignore>.
- A classic example for files to ignore globally are `.DS_Store` files on macOS.
## Once it's in, it's too late
Once a file is tracked by `git`, adding it to the `.gitignore` will not do anything.
- You will first have to remove it from git
- **Option 1:** Delete the file and commit the deletion
- **Option 2:** Remove file from index only (and commit)
- `git rm --cached <file>`
- ⚠️ Warning: This will delete the file for anyone else working with the repository!
## Practical: Ignoring Files {background-color="black"}
1. Go back to your VSCode Terminal in `git-exercise`
2. Google for a git cheatsheet (it should be a PDF file)
3. Copy the PDF into your `git-exercise` directory
4. Create a new .gitignore file to ignore only this cheatsheet
5. Commit the .gitignore file
## *End of Section* 🎉 {background-color="black"}
:::{.r-fit-text}
Any Questions?
:::
[[🏡 Back to Overview]](./index.html)
[[⏩️ Next Section]](./2.2-history.html)