Is there an ignore command for git like there is for svn?
Solution 1
There is no special git ignore
command.
Edit a .gitignore
file located in the appropriate place within the working copy. You should then add this .gitignore
and commit it. Everyone who clones that repo will than have those files ignored.
Note that only file names starting with /
will be relative to the directory .gitignore
resides in. Everything else will match files in whatever subdirectory.
You can also edit .git/info/exclude
to ignore specific files just in that one working copy. The .git/info/exclude
file will not be committed, and will thus only apply locally in this one working copy.
You can also set up a global file with patterns to ignore with git config --global core.excludesfile
. This will locally apply to all git working copies on the same user's account.
Run git help gitignore
and read the text for the details.
Solution 2
A very useful git ignore command comes with the awesome tj/git-extras.
Here are a few usage examples:
List all currently ignored patterns
git ignore
Add a pattern
git ignore "*.log"
Add one of the templates from gitignore.io
git ignore-io -a rails
git-extras provides many more useful commands. Definitely worth trying out.
Solution 3
On Linux/Unix, you can append files to the .gitignore file with the echo
command. For example if you want to ignore all .svn
folders, run this from the root of the project:
echo .svn/ >> .gitignore
Solution 4
You have two ways of ignoring files:
.gitignore
in any folder will ignore the files as specified in the file for that folder. Using wildcards is possible..git/info/exclude
holds the global ignore pattern, similar to theglobal-ignores
in subversions configuration file.
Solution 5
Create a file named .gitignore on the root of your repository. In this file you put the relative path to each file you wish to ignore in a single line. You can use the *
wildcard.
Chris J
Updated on December 19, 2020Comments
-
Chris J over 3 years
I am a new user to
git
and I am starting a new project. I have a bunch of dot files that I would like to ignore. Is there an ignore command forgit
like there is forsvn
?-
Gene Bo almost 9 yearsGood alternative to gitignore: git update-index --assume-unchanged <file> , thanks to stackoverflow.com/a/16442091/2162226
-
-
Anonigan over 14 yearsNote that patterns in
.gitignore
file which do not contain '/' are matched recursively (i.e. also in all subdirectories of the directory the.gitignore
file is in), contrary to the case ofsvn:ignore
directory properties in Subversion. -
jcollum about 12 yearsNot having a simple ignore command seems like such an oversight on the part of the git team.
-
Archangel33 over 8 yearsThe answer here expands $1 correctly: stackoverflow.com/a/21884533/1465227
-
JohnAndrews over 8 yearsSo if I use git ignore "index.html" it will ignore this file?
-
JohnAndrews over 8 yearsI found out this tweet using that syntax twitter.com/noodl_io/status/669904872704253953
-
Bynho over 8 yearsIs the -t command still applicable? When I run it, it just adds the -t and whatever template I try to add into the git ignore file
-
Ryan about 8 yearsIn Git Bash on Windows, I needed to add a preceding
/
and trailing '\' (to create a new line), such asecho /nbproject/project.properties\ >> .gitignore
andecho /nbproject/project.xml\ >> .gitignore
. -
Alex Glover about 5 yearsOn Mac, if you have Homebrew installed, you can run
brew install git-extras
. -
abelito about 5 years@jcollum At first glance it does, but the simplicity of aliasing a command to add new ones AND the complexity of creating one and working through all the edge cases/gotchas/potential issues of editing a text file also makes sense to leave it to the user. I feel conflicted because I both agree and disagree with you.
-
RBT almost 3 yearsThat forward slash
/
character in the end is of paramount importance. Without it, the new rule gets appended to the last entry already existing in the.gitignore
file in place of getting created as a new entry at the bottom of the file.