Is it possible to keep a feature branch totally in sync with the main branch except for a couple of specific files?
So for example I have a branch I create specifically for trying out a new style which has some changes to a css file, I'm not sure whether to go with the new style but I want to keep the option open while I continue to work on my app in main... when I switch back to my style branch all my progress in main is no longer there so I can't see what my updated app looks like with my alternate style..
So to keep the 2 in sync while excluding the style file would be perfect!
I've tried to look up how I might do this but haven't managed to come across what I'm looking for..
Thanks for any help you can give!
CodePudding user response:
I think you're already taking the right approach: create a separate branch for your "special CSS".
You can (and should) frequently merge changes in "main" back to your "dev" branch, to keep everything in sync.
Unless that particular CSS file is changing in "main", the merge shouldn't affect your branch.
Otherwise, you might consider looking into .gitattributes:
- Can I prevent a certain file from being merged to another branch but still keep it under version control?
- How to make Git preserve specific files while merging
- gitattributes - Defining attributes per path
CodePudding user response:
You can merge your main
branch to your style
branch if your css
files in main
branch does not change.
If both .css
files in your main
branch and style
are changed, you can create a new dev
branch for developing new features, and only modify your styles in main
branch or style
branch. When preview with desired styles, just merge the dev
branch to main
branch or style
branch, the styles will not affected as the style files are not modified in dev
branch.