Preserving local changes during git pull

By the time I got a branch done there were several new merges; the branch’s compare page on github is full of differences with things that other people changed.
Currently, if I use ‘git pull upstream master’ on my branch, it says
"error: Your local changes to the following files would be overwritten by merge:
Please, commit your changes or stash them before you can merge.
and if I use it on master it says it’s up to date.

Is there any way to add new ‘official’ changes to my branch without overwriting existing ones, or am I stuck with rewriting/copy-pasting all my code back into place?

There are several ways to do this.
I think this is the easiest.
git stash save
git pull upstream master
git stash apply

Stash save takes your changes and stashes them in a special area maintained by git, then stash apply puts them back on top of the changes in your branch.
If there is a conflict (a place where something you modified was also modified upstream), it will happen when you do git stash apply. Recovering from it will be relatively easy since your changes are still there in the stash.

Some other things you can do to make this easy.
Don’t make changes on your master branch, which is the only thing you would want to do “git pull” on.

If you need to update a later branch you can do this instead of git pull.

  1. commit any changes that are still floating around
  2. “git fetch upstream master”
  3. “git merge -X patience FETCH_HEAD” (the patience argument makes it take a couple extra seconds and removes a lot of horrible conflicts that pop up in JSON files).
  4. fix any merge conflicts in the program files and save them
  5. if changes needed to be made do “git add file/spot/here”
  6. if changes are all fixed do “git commit”
  7. “git push” to update your branch and any linked PR’s