Ways to Exclude Files in GIT ?
1. Exclude Files with git add Using Patterns
git add Using PatternsStage all files except README.md
README.mdgit add -- ':!README.md'Stage all .js files except test.js
.js files except test.jsgit add -- '*.js' ':!test.js'2. Exclude Files Temporarily Using .gitignore
.gitignore# Ignore README.md
README.md
# Ignore all .log files
*.log
# Ignore specific folder
/temp/3. Exclude Files Using git rm with Patterns
git rm with PatternsStage all files
Remove README.md from the staging area:
README.md from the staging area:4. Use git update-index to Skip Files
git update-index to Skip FilesSkip changes in README.md:
README.md:Revert the skipping:
Use Glob Patterns in Command-Line
Stage all .css files except style.css:
.css files except style.css:Exclude files with a certain prefix:
5. Use Negation in .gitignore
.gitignoreExample .gitignore:
.gitignore:6. Exclude Files in Aliases
Add an alias in your Git config:
Use the alias:
Last updated