Configure git to ignore some files locally
📅April 1, 2021
🗁Git
In this short article, we will show you how to configure git to ignore some files locally.
Sometimes, You may need to exclude files from Git only on your computer. So you can use the simple git command to ignore the files locally without using the `.gitignore` file.
Checkout more articles on Git
- List of Git commands
- Delete all commit history in GitHub
- Multiple SSH keys for different GitHub accounts
Ignore files
git update-index --skip-worktree <file-list>
</file-list>
Unignore files
git update-index --no-skip-worktree <file-list>
</file-list>
Get the list of ignored files
git ls-files -v | grep ^S
Install git aliases
You can install git aliases to make it simpler. It will update your aliases node of your config file.
git config --global alias.ignore 'update-index --skip-worktree'
git config --global alias.unignore 'update-index --no-skip-worktree'
git config --global alias.ignored '!git ls-files -v | grep ^S'
Now run the following commands to ignore/unignore or get ignored file list.
// Ignore files
git ignore <file-list>
// Unignore files
git unignore <file-list>
// Get ignored files
git ignored
</file-list></file-list>
That’s it for today.
Thank you for reading. Happy Coding..!! 🙂