1

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!

paulsm4
  • 114,292
  • 17
  • 138
  • 190
treeseal7
  • 739
  • 8
  • 22

2 Answers2

2

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:

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • ah perfect thanks, the .gitattributes file seems to be doing the job! so to clarify, the best way to keep a feature branch is sync with main, is to simply go into the branch and then merge with main? so just kind of a habit to get into rather than something that can be automated? – treeseal7 May 26 '22 at 17:23
  • 1
    Yes, exactly :) And yes, if you wish, anything in Git can be "automated" (for example, write a script with the appropriate git command line(s)). – paulsm4 May 26 '22 at 18:30
0

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.

Acane
  • 167
  • 1
  • 9