4 ms·
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 te
by jakub_g 8mo 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`
- theowaway213456 8mo ago.git/info/exclude is mentioned in the first section (about .gitignore)
- jakub_g 8mo agoOops, I've glanced over it too fast. Thanks - updated my post.
- jmholla 8mo agoHere'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): git-ignore-local () { root=$(git rev-parse --show-toplevel) path=$(readlink -f "$1") # ${path#${root}} should suffice if you don't have realpath relpath=$(relpath -m --relative-to="$root" "$path") echo "$relpath" >> "${root}.git/info/exclude" } 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`.
- jmholla 8mo agoWhoops, there should be a slash after `${root}` in that last line.
- jakub_g 8mo agoFYI: 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.
- anitil 8mo agoWow 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.