Can I ignore files locally without polluting the global git config for everyone else? I have untracked files that are spam in my git status but I don\'t want to commit git c
If your repo doesn't already have a .gitignore file, then a simple solution is to create a .gitignore file, and in it add .gitignore
to the list of files to be ignored.
Both --assume-unchanged and --skip-worktree are NOT A CORRECT WAY to ignore files locally... Kindly check this answer and the notes in the documentation of git update-index. Files that for any reason keep changing frequently (and/or change from a clone to another) and their changes should not be committed, then these files SHOULD NOT be tracked in the first place.
However, the are two proper ways to ignore files locally (both work with untracked files). Either to put files names in .git/info/exclude file which is the local alternative of .gitignore but specific to the current clone. Or to use a global .gitignore (which should be properly used only for common auxiliary files e.g. pyz, pycache, etc) and the file will be ignored in any git repo in your machine.
To make the above as kind of automated (adding to exclude or global .gitignore), you can use the following commands (add to your bash-profile):
.git/info/exclude
~/.gitignore
Linux
alias git-ignore='echo $1 >> ##FILE-NAME##'
alias git-show-ignored='cat ##FILE-NAME##'
git-unignore(){
GITFILETOUNIGNORE=${1//\//\\\/}
sed -i "/$GITFILETOUNIGNORE/d" ##FILE-NAME##
unset GITFILETOUNIGNORE
}
MacOS (you need the .bak for sed
inplace modifications (i.e. you are forced to add a file extension to inplace sed. i.e. make a backup before replacing something), therefore to delete the .bak file I added rm filename.bak)
alias git-ignore='echo $1 >> ##FILE-NAME##'
alias git-show-ignored='cat ##FILE-NAME##'
git-unignore(){
GITFILETOUNIGNORE=${1//\//\\\/}
sed -i.bak "/$GITFILETOUNIGNORE/d" ##FILE-NAME##
rm ##FILE-NAME##.bak
unset GITFILETOUNIGNORE
}
Then you can do:
git-ignore example_file.txt
git-unignore example_file.txt
Add the following lines to the [alias] section of your .gitconfig file
ignore = update-index --assume-unchanged
unignore = update-index --no-assume-unchanged
ignored = !git ls-files -v | grep "^[[:lower:]]"
Now you can use git ignore my_file
to ignore changes to the local file, and git unignore my_file
to stop ignoring the changes. git ignored
lists the ignored files.
This answer was gleaned from http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html.
You have several options:
.gitignore
file in your working dir (or apply it automatically using topgit or some other such patch tool).$GIT_DIR/info/exclude
file, if this is specific to one tree.git config --global core.excludesfile ~/.gitignore
and add patterns to your ~/.gitignore
. This option applies if you want to ignore certain patterns across all trees. I use this for .pyc
and .pyo
files, for example.Also, make sure you are using patterns and not explicitly enumerating files, when applicable.
In order to ignore untracked files especially if they are located in (a few) folders that are not tracked, a simple solution is to add a .gitignore
file to every untracked folder and enter in a single line containing *
followed by a new line. It's a really simple and straightforward solution if the untracked files are in a few folders. For me, all files were coming from a single untracked folder vendor
and the above just worked.