Skip to content

Commit 8328982

Browse files
committedOct 23, 2023
📝 doc: add trick for global .gitignore file
1 parent 9fd0eae commit 8328982

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed
 

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
.DS_Store

‎tricks/README.md

+29-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,37 @@
55
### Ignore files
66
- Add those files to `.gitignore`
77
- To use specific template for specific project, take a look at https://github.com/github/gitignore
8+
- Nice .gitignore generators:
9+
- https://github.com/simonwhitaker/gibo
10+
- https://www.toptal.com/developers/gitignore/
11+
12+
### Global .gitignore
13+
- Reason to why we need a global .gitignore: Local .gitignore should be used for objects that should not be versioned, but still within the scope of the repo. In the case of system-specific files, it's a good practice to use global .gitignore.
14+
- Solution:
15+
- [RECOMMEND] the conventional global .gitignore file is `~/.config/git/ignore`
16+
- [OLD_SOLUTION] create a .gitignore file and attach it with git
17+
- Step 1: Create a new .gitignore file in anywhere you want
18+
19+
```bash
20+
touch ~/.gitignore
21+
```
22+
23+
- Step 2: attach that file with git's global settings
24+
25+
```bash
26+
git config --global core.excludesfile ~/.gitignore
27+
```
28+
29+
- You can verify the global .gitignore location by `git config --global core.excludesFile`
30+
- A nice global .gitignore template: https://github.com/github/gitignore/tree/main/Global
31+
32+
- References:
33+
- https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer
34+
- https://gist.github.com/subfuzion/db7f57fff2fb6998a16c
835

936
### Share git hooks with team
1037
- Reason: git hooks stay in `.git`, hence not pushed to remote repository -> got to find a workaround to share these hooks with team
11-
- Solution: create a folder called `scripts` or `.githooks` or `git-scripts` (or any name you want) in your local repo, and use
38+
- Solution: create a folder called `scripts` or `.githooks` or `git-scripts` (or any name you want) in your local repo, and use one of these methods:
1239
- [RECOMMEND] config hooks path with
1340

1441
```bash
@@ -21,7 +48,7 @@
2148
ln -s <folder_name> ".git/hooks"
2249
```
2350
- SUPER TIP: Automate the sharing process by putting any githook setup to a script and ask your team to run it. Example:
24-
51+
``
2552
```bash
2653
#!/bin/bash
2754
@@ -230,9 +257,7 @@
230257
- Reference: https://opensource.com/article/20/10/advanced-git-tips
231258
232259
## TODO
233-
- revert a commit by hash
234260
- cherry pick
235-
- global gitignore
236261
- write a script to prepare tips needed for a project, e.g., prepare githooks, config aliases
237262
238263
- Ref:

0 commit comments

Comments
 (0)
Please sign in to comment.