There is no explicit git ignore command: instead the . gitignore file must be edited and committed by hand when you have new files that you wish to ignore. . gitignore files contain patterns that are matched against file names in your repository to determine whether or not they should be ignored.
Use your favorite text editor to open the file called .git/info/exclude within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.
gitignore should list the names or name-patterns of files that will be found in work-trees when working with your project, but that should not be committed to the project. In other words, it's not OS-specific, it's project-specific.
gitignore file tells Git which files to ignore when committing your project to the GitHub repository. gitignore is located in the root directory of your repo. / will ignore directories with the name.
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.
A very useful git ignore command comes with the awesome tj/git-extras.
Here are a few usage examples:
git ignore
git ignore "*.log"
git ignore-io -a rails
git-extras provides many more useful commands. Definitely worth trying out.
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
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 the global-ignores
in subversions configuration file.I hope it's not too late.
If you are on Windows you can just do the following to create a .gitignore file
echo name_of_the_file_you_want_to_ignore.extension > .gitignore
In order to edit .gitignore you can run
notepad .gitignore
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.
It's useful to define a complete .gitignore file for your project. The reward is safe use of the convenient --all
or -a
flag to commands like add
and commit
.
Also, consider defining a global ~/.gitignore file for commonly ignored patterns such as *~
, which covers temporary files created by Emacs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With