Today I had to update my git branch with fixes made to other parts of the repo. Since I am in the middle of development changes, I couldn't just pull down a fresh branch.
These updates were necessary as the API had breaking changes that required fixes in index.jsx in order for the app to still work with REST, so I had to update my branch to include these changes.
A quick search yielded a simple and workable solution on Stack Overflow.
The steps to sync a branch with main are as follows:
git checkout { main || master }
git pull
git checkout { branch }
git merge { main || master }
This will create a messy merge history, unfortunately, but gets the work done for now. I need to research a better solution moving forward.
To update my branch with a patch made elsewhere in the repo without overwriting my uncommmitted code.
Updated the branch, code under development was not affected.
My uncommitted code appears to not be affected. However, the API changes that broke the app are no longer breaking the app.
The breakage in the app has been patched without affecting the code currently being worked on.
Being comfortable pulling in patches to branches not in sync with main is an important skill to be used to doing frequently and comfortably.
Even for changes not obviously blocking development, this can be a good idea for PRs merged that might affect my current work, as it would avoid potentially breaking the app with my PR and requiring a fix on a separate PR. Instead, I can validate that my current code works with the current (and not old) state of main before I submit a PR.