How to copy a file from one git branch to another

You’re working on a branch. Let’s say it’s the master branch.

You have another branch. Let’s call it abandoned.

You don’t care about the abandoned branch, except for one useful file. Let’s call it useful.txt.

Don’t do this:

$ git checkout abandoned

[human manually copies `useful.txt` to their clipboard]

$ git checkout master

[human manually creates a new file and pastes into it]
Instead, do this:
$ git checkout master
$ git checkout abandoned useful.txt

😸

updatedupdated2021-01-192021-01-19