If I am in master and stuff I want safe from git is ignored, I then:
git checkout <oldbranch or commit>
But the old branch doesn't have the ignored files arrgh! So now the untracked files could get added etc and are vulnerable to reset --hard etc.
Is there more elegant fix here other than:
git checkout master .gitignore
#maybe write a hook to do this every checkout of <oldbranch or commit>?
Or constantly manage copying .gitignore into .git/info/exclude?
Adding rules in .git/info/exclude is one way, but it remains a local workaround: it won't get pushed like a .gitignore file would.
The best option remains to create the .gitignore in the checked out branch:
git checkout aBranchWithoutGitignore
git checkout master -- .gitignore
git add .gitignore
git commit -m "Add .gitignore from master"
Then cherry-pick that commit to other branches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With