The simplest method is to create a file:. gitignore in the same directory as the. Git directory.
Touch. gitignore
Vi. gitignore
: WQ
Note: If the file to be ignored has been managed by git, you need to remove it first. The command is as follows:
E.g .:
Git Rm-r -- cached webroot/WEB-INF/classes /**/*
-R: Recursion
Git commit
Then, the ignore in. gitignore takes effect.
Reference //-------------------
From:
Http://gitready.com/beginner/2009/01/19/ignoring-files.html
The easiest and simplest way is to create.gitignore
File in your project's root directory. The files you choose to ignore here take affect for all directories in your project, unless if they include their own.gitignore
File. this is nice since you have one place to configure ignores unlike SVN's SVN: Ignore which must be set on every folder. also, the file itself can be versioned, which is definitely good.
Here's a basic.gitignore
:
$ cat .gitignore# Can ignore specific files.DS_Store# Use wildcards as well*~*.swp# Can also ignore all directories and files in a directory.tmp/**/*
Of course, this cocould get a lot more complex. You can also add exceptions to ignore rules by starting the line!
. See an example of this at the GitHub guide on ignores.
Two things to keep in mind with ignoring files: First, if a file is already being tracked by git, adding the file.gitignore
Won't stop git from tracking it. You'll need to dogit rm --cached <file>
To keep the file in your tree and then ignore it. secondly, empty directories do not get tracked by git. if you want them to be tracked, they need to have something in them. usually doingtouch .gitignore
Is enough to keep the folder tracked.
You can also open up$GIT_DIR/info/exclude
($GIT_DIR
Is usually your.git
Folder) and edit that file for project-only ignores. the problem with this is that those changes aren't checked in, so use this only if you have some personal files that don't need to be shared with others on the same project.
Your final option with ignoring folders is adding a per-user ignore by setting upcore.excludesfiles
Option in your config file. You can set up.gitignore
File in yourhome directory that will affect all of your repositories by running this command:
git config --global core.excludesfile ~/.gitignore
Read up on the manpage if you 'd like to learn more about how ignores work. As always, if you have other ignore-related tips let us know in the comments.