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
.gitignore
files for each branch and name it like this :.gitignore.branch_name
- In your git repo, go to
.git/hooks/
- Edit or create
post-checkout
file 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 !
If I push a file in a "private" branch and have that file ignored in the "master" branch, performing a merge of private into master will still commit that file and make it publicly accessible.
Is this working as intended?
I checked that my exclude file has the correct exclusions but it seems like you cannot exclude files from a merge. I read @dberardo-com statement of "limits the power of this solution" as exactly this problem. Is that correct? Is there a solution where I can prevent ignored files from getting merged into the public branch?