Comment by jakub_g
4 days ago
I'd like to emphasize the `.git/info/exclude`, which is a "repo-local gitignore", i.e. only for you and only for this repo.
Useful when you want to create a temporary file to help you e.g. with a bug investigation, and make sure it stays untouched while you switch branches, and to avoid accidentally committing it.
I have a shell alias like this:
git-ignore-local () {
echo "$1" >> .git/info/exclude
}
and use it like `git-ignore-local myfile.ext`
Here's a little extra magic so that you don't even need to be in the root of the repository to create such a temporary file (you'll have to change the readlink invocation if you're on MacOS):
Edit: You could also put the function contents as an executable on your PATH called `git-ignore-local` then it becomes something you can invoke as `git ignore-local`.
FYI: you may want to check `git rev-parse --show-cdup`
- in root of the repo, it prints empty string
- if you're 1 level deep it prints `../`
- if you're 2 levels deep it prints `../../`
One minor drawback: inside `.git` subfolder, it always prints empty string too.
Whoops, there should be a slash after `${root}` in that last line.
.git/info/exclude is mentioned in the first section (about .gitignore)
Oops, I've glanced over it too fast. Thanks - updated my post.
Wow TIL thankyou! I've got a bunch of small things like this in my current project that always complicate my PRs, this will solve that handily.