Short Answergit checkout origin/master -- path/to/file // git checkout <local repo name (default is origin)>/<branch name> -- path/to/file will checkout the particular file from the downloaded changes (origin/master).
Downloading a Single File From The Github Website You can copy/paste from here, but in most browsers, you should be able to right click and select “Save As” to download the file directly. For code files, it may try to save as . txt , which you will need to fix manually before or after downloading.
Here is a slightly easier method I just came up with when researching this:
git fetch {remote}
git checkout FETCH_HEAD -- {file}
You can fetch and then check out only one file in this way:
git fetch
git checkout -m <revision> <yourfilepath>
git add <yourfilepath>
git commit
Regarding the git checkout
command:
<revision>
-- a branch name, i.e. origin/master
<yourfilepath>
does not include the repository name (that you can get from clicking copy path
button on a file page on GitHub), i.e. README.md
git checkout master -- myplugin.js
master = branch name
myplugin.js = file name
@Mawardy's answer worked for me, but my changes were on the remote so I had to specify the origin
git checkout origin/master -- {filename}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With