Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wget a raw file from Github from a private repo

I am trying to get a raw file from github private project using wget. Usually if my project is public it is very simple

For Public Repo This is my repo url (you don't have to click on it to answer this question)

https://github.com/samirtendulkar/profile_rest_api/blob/master/deploy/server_setup.sh

I click raw enter image description here

After I lick raw My URL looks like this

https://raw.githubusercontent.com/samirtendulkar/profile_rest_api/master/deploy/server_setup.sh (Notice only the word "raw" is added to the URL)

which is awesome I then do

ubuntu@ip-172-31-39-47:~$ wget https://raw.githubusercontent.com/samirtendulkar/profile_rest_api/master/deploy/server_setup.sh

when I do ls it shows that the file has been downloaded

ubuntu@ip-172-31-39-47:~$ ls
'server_setup.sh'

For a Private repo The raw file comes with a token

https://github.com/samirtendulkar/my_project/blob/master/deploy/server_setup.sh

So far so good Now when I click Raw (see image above) My URL changes and has a token in it along with the "raw" prefix

https://raw.githubusercontent.com/samirtendulkar/my_project/master/deploy/server_setup.sh?token=AkSv7SycSHacUNlSEZamo6hpMAI6ZhsLks5b4uFuwA%3D%3D

The url has these extra parameters ?token=AkSv7SycSHacUNlSEZamo6hpMAI6ZhsLks5b4uFuwA%3D%3D

My wget does not work. How Do I fix this issue. By the way when I say it does not work I mean instead of the ls showing

ubuntu@ip-172-31-39-47:~$ ls
    'server_setup.sh'

It shows as below

enter image description here which is not making me run futher commands like

ubuntu@ip-172-31-39-47:~$ chmod  +x server_setup.sh

and

ubuntu@ip-172-31-39-47:~$ sudo ./server_setup.sh

which I need to get the project on to AWS enter image description here

like image 683
Samir Tendulkar Avatar asked Oct 31 '18 12:10

Samir Tendulkar


2 Answers

The token is from the Personal Access Tokens section that you can find the details in Github.

With Personal Access Tokens, you can create one and pick the first option "repo" to get access control over the private repos for the token.

following line solved my problem which was not being able to download the file.

Hope this will help

wget --header 'Authorization: token PERSONAL_ACCESS_TOKEN_HERE' https://raw.githubusercontent.com/repoOwner/repoName/master/folder/filename
like image 163
BarisJKC Avatar answered Oct 09 '22 06:10

BarisJKC


You can use wget's -O option when you're downloading just one file at a time:

wget -O server_setup.sh https://raw.githubusercontent.com/samirtendulkar/my_project/master/deploy/server_setup.sh?token=AkSv7SycSHacUNlSEZamo6hpMAI6ZhsLks5b4uFuwA%3D%3D

The downside is that you have to know the output file name, but I think that's OK if I understand your question well.

like image 33
joanis Avatar answered Oct 09 '22 07:10

joanis