With Git 2.23 (August 2019) and the new (still experimental) command git restore
, seen in "How to reset all files from working directory but not from staging area?", that would be:
git fetch
git restore -s origin/master -- path/to/file
The idea is: git restore
only deals with files, not files and branches as git checkout
does.
See "Confused by git checkout
": that is where git switch
comes in)
codersam adds in the comments:
in my case I wanted to get the data from my upstream (from which I forked).
So just changed to:git restore -s upstream/master -- path/to/file