-
Notifications
You must be signed in to change notification settings - Fork 0
Ignore Files and Folders
Edit the file:
-
.git/info/excludeto ignore files that exists only in your local repository. (for example temporary files generated by a local smoke test you are the only one to use)..git/info/excludeis not under version control. Use it to ignore files specific to your local configuration. -
.gitignoreto ignore files in your local repository and in any clone of your repository. (This file contains files (and folders) ignored by default for anyone cloning (or pulling from) this repository).gitignoreis under version control and shared by anyone using the repository. Once commited and pushed to the repository, file exclusion configured in.gitignoreapplies to whoever uses the repository.
The exclusion rule for a file/folder must be added in either of these files, before git begins tracking it.
If you need to ignore a file after git started tracking it, see git update-index --assume-unchanged below.
You can also define a global gitignore file that will apply to whatever repository.
git config --global core.excludesfile ~/gitignore.globalGithub contains a list of per language gitignore file templates: https://github.com/github/gitignore/tree/master/Global
Use it as an inspiration as to what to put in ~/gitignore_global.
List the ignore/exclusion rules as defined in .gitignore and .git/info/exclude.
git status --ignored
.agignore
.bundle/
.idea/
public/docs/.DS_Store
tagsIf you have trouble remembering the above command, you use create this handy alias:
git config --global alias.ignored "status --ignored"
# From now on you can use the following instead
git ignoredYou may sometimes need to ignore a file already tracked by git.
Using the files .gitignore or .git/info/exclude won't work in this case but the following command may come in handy.
Run the following command to temporarily exclude a file from git tracking, pretending it never changed.
We hide this file from git.
git update-index --assume-unchanged FILE
Later on, if you need to commit changes to this file, simply use the opposite command to unhide this file from git:
git update-index --no-assume-unchanged FILE
If you want to unhide all hidden files:
git update-index --really-refresh
To list the files hidden from git, use this:
git ls-files -v | grep '^[a-z]' | cut -c3-
The below aliases may come in handy if you intend to use the above commands on a regular basis or need an easier way to remember them without the syntax burden.
git config --global alias.hide 'update-index --assume-unchanged`
git config --global alias.unhide 'update-index --no-assume-unchanged`
git config --global alias.unhide-all 'update-index --really-refresh'
git config --global alias.hidden '!git ls-files -v | grep '^[a-z]' | cut -c3-'