Assuming you just want to overwrite the contents of that file in your working copy (so that it will show up as "modified" in the output of git status
, then you can do it this way:
Update the remote tracking branches of your local repository using git fetch
. This does not modify any local branches, nor your working copy:
git fetch --all
Use git show
to obtain a copy of the file from the remote branch, and write that to disk by redirecting standard output:
git show origin/master:whatever/whatever.py > whatever/whatever.py
By specifying origin/master
you are copying the file from the remote tracking branch, which will be the latest version of that file as of the git fetch
. You can of course redirect the standard output to overwrite the existing file as shown above, or to write the output elsewhere.
The git show
command accepts other formats as well: see "SPECIFYING REVISIONS" in man gitrevisions
.
Note that, as @bluefeet commented on their answer, if you commit this file to your local branch, and your local branch is intended to be merged with the remote master later, then your locally copied whatever/whatever.py
will be in conflict with the changes from the remote tracking branch. So generally, you would only do this as a temporary measure to test something, or if you have no intent of merging your local branch with the remote master later.