When I rode in hills, I just did my best to keep my knees going straight up and down. Forty years ago, I had a knee problem, and a doc looked at me pedal on a trainer. His prescription was to 'spin like hell', because that gave my knees the most natural motion. YMMV.
If I were climbing hills, I'd do the same things I do on the flats: if I felt no pain, I'd continue doing what I was doing. If I feel pain, I adjust the angle of my foot on the pedal until I found a painless position. If I couldn't find a painless position, I'd slow down or even stop pedaling and, perhaps, feel sorry for myself.