How to ignore several directories in Git
I’m going to be uploading several files to a community Git project, and I am only supposed to upload certain files without permission, then ask for permission to upload all the rest should I need to change them. So, I would like Git to just ignore all the directories I don’t have permission to freely change, so I can freely upload what I want, and then should the need arise, upload the directories I’ve changed that I don’t have permission to.
What would be the best way about doing this?
One Solution collect form web for “How to ignore several directories in Git”
If those directories (you don’t have permission to change directly) are already versioned, I wouldn’t recommend a
.gitignore solution as:
- you risk to add, commit and push that
.gitignore(which the remote repo doesn’t want to change)
- it wouldn’t work anyway, without removing those folders from the index (
git rm -r --cached /folders/you/dont/have/permission), which in turn risk to be committed and push (the remote repo wants those folders!)
It is best to apply a local solution (which doesn’t risk to be pushed by mistake).
Before adding anything, do (for the folder you don’t have permission) a:
git update-index --skip-worktree -- /folder
See “using git skip-worktree to disable file updates”.
git add and
git commit should ignore that already versioned folder, even if you have modified/added files in it.
You can reverse that local change with a:
git update-index --no-skip-worktree -- /folder