My objective is to have some production files ignored on specific branches. Git doesn't allow to do it.
My solution is to make a general .gitignore file and add .gitignore.branch_name files for the branches I want to add specific file exclusion.
I'll use post-checkout hook to copy those .gitignore.branch_name in place of .git/info/exclude each time I go to the branch with git checkout branch_name.
- Create new
.gitignorefiles for each branch and name it like this :.gitignore.branch_name - In your git repo, go to
.git/hooks/ - Edit or create
post-checkoutfile and copy the content found in this gist. - Don't forget to make it executable with
chmod 755 post-checkout - Just go to the branch you want and type
git status: TADAAA !
@CodeSmile-0000011110110111 The solution is that you create another repository for code changes to the master. That repository accepts changes from the private branch and then changes the .gitignore file before merging into the master branch. You can automate this with GitHub actions.
Also if possible, changes should only move from the master to the private branch.