4

I want to fetch a single file from a git repository. Using SVN, I can use svn export as follows:

sudo svn export http://www.example.com/repos/Trunk/pathtofile/file.ext

This just downloads the file, naked, i.e without any repository info with it.

Is there an equivalent to svn export in git?

The closest I got was "git show upstream/master:pathtofile/file.ext" but this isn't really equivalent because you already need to be inside a git repo for it to work.

Another option I have, because I'm using github, is to try to wget the github raw file.

wget https://raw.github.com/<mygithubuser>/repo/master/pathtofile/file.ext?login=<mylogin>&token=<notsurewhattoputhere>

The problem is that the repo is private so I need to supply a token and I'm not sure how to generate this and use it in a wget?

3

3 Answers 3

2

I've not checked, but according to this git hub page your authentication token is supplied on you profile page. So assuming it's an option to just manually embed it in the command, then I'd go for that. Otherwise I suppose you'd need to accept it as a parameter to the script this command will be contained in, or possibly in a configuration file. Although I guess both of those options could have security concerns.

Sign up to request clarification or add additional context in comments.

6 Comments

That github page looked very promising. Unfortunately, I wasn't able to get a wget working even though I was using the token as specified.
Odd, that page certainly seems to imply that the token based authentication should work anywhere. I don't have access to any private repos myself to test anything out myself though. Did you enclose the URL in quotes when running wget? Just ask because that's a mistake I commonly make, and I notice they're missing in your example command above.
Also, have you tried supplying the username & token as POST parameters? That seems to be what the example from that link does with it's -F parameter to curl
YES YES YES - It worked when I enclosed the URL in quotes when running wget. I didn't know that was needed. Thanks @obmarg.
No problem. It's needed because the shell treats & (and possibly ?) as special characters, so you either need to escape them or enclose the whole parameter in quotes, just as you would if the url contained spaces.
|
2

If the repo is in GitHub then just use svn export!

svn export https://github.com/username/repo-name/trunk/pathtofile/file.ext

1 Comment

Upvoted for the github svn support link! Not a very widely known fact.
1

I would not put the token and username in the query string. Instead do something like this:

curl -F 'login=mylogin' -F 'token=mytoken' https://raw.github.com/<mygithubuser>/repo/master/pathtofile/file.ext > /tmp/file.ext

As for why you should not put it in the QS this is a good explanation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.