2

I forked someone else's repository and am developing on it. Some changes I make should go upstream, some others are specific to my usecase.

If I add a feature that should be sent upstream and also is needed for my own usecase, I have to checkout the upstream commit, make the change, and then checkout my working commit and make the change again.

I have to make the changes twice to do this. Is there an easier way?

user3180
  • 1,369
  • 1
  • 21
  • 38

1 Answers1

2

This is what merging branches is for!

Your work is based on the “upstream” branch. So you can make your change in that branch, then merge it back into your own to get those changed.

git checkout upstream
(Edit)
git commit
git checkout mine
git merge upstream
Bob Jacobsen
  • 1,150
  • 6
  • 9
  • Ah, I see... but I would prefer if I could make the changes in the working commit and merge a single file to the upstream... i believe this is the solution https://stackoverflow.com/questions/10784523/how-do-i-merge-changes-to-a-single-file-rather-than-merging-commits/11593308 – user3180 Jan 20 '19 at 09:32
  • @user3180: that's not an actual merge. If it does what you want, that's OK, just be aware that you haven't really done a *merge*, you've just patched-up one file. – torek Jan 20 '19 at 16:53
  • You can branch from upstream, work on that until your happy, then (optionally rebase multiple commits to one) and send that branch to the upstream group cleanly. Meanwhile, you can merge that work-in-progress into your working branch for testing as often as you’d like. – Bob Jacobsen Jan 20 '19 at 17:09