2

This must be something basic but I can't figure it out. I have a github URL that has the form "https://.../tree/main". How do I download the contents? In response to

git clone https://.../tree/main

I get

fatal: repository 'https://.../tree/main/' not found

When I do

git clone https://.../

I get the contents of the root folder but not the subfolder that I want.

What am I doing wrong?

4
  • What is the output of git branch --show-current?
    – Daniel B
    Commented Jun 15, 2021 at 19:50
  • @DanielB When I do git branch https://.../tree/main --show-current and git branch https://.../ --show-current I get fatal: not a git repository (or any of the parent directories): .git
    – I Z
    Commented Jun 15, 2021 at 20:14
  • Please don't modify commands. You must run this command in the folder where the cloned repository resides.
    – Daniel B
    Commented Jun 15, 2021 at 20:16
  • When I do git branch --show-current I get the same exact error message. But why would I expect anything else? I am in my local folder that I just created and I am trying to clone the repo for the first time.
    – I Z
    Commented Jun 15, 2021 at 20:28

3 Answers 3

1

A GitHub HTTPS URL is of the form https://github.com/OWNER/NAME, with an optional .git on the end. The URL you're using, with /tree/main, is designed to render the main branch in the user interface, but that isn't a valid repository and you can't use it with Git.

If it's the case that you want to look at the main branch in the repository, then clone it using a proper URL, and then run git checkout -b main origin/main, which will create a main branch that's a copy of the remote branch. If you're already on the branch main, then that won't work, and you can just look at the repository once it's cloned.

0

You can see this error also when the repository is empty.

shell> git clone https://repos.example.org/test_001.git
Cloning into 'test_001'...
fatal: repository 'https://repos.example.org/test_001.git/' not found

This means it is not enough to create on the server an empty repository for testing

admin# pwd
/usr/local/www/repos.example.org
admin# git init --bare test_001.git

Note: For example, a virtual host in Apache

admin# cat /usr/local/etc/apache24/extra/repos.example.org.conf 
     <VirtualHost *:80>
     ServerName repos.example.org
     DocumentRoot /usr/local/www/repos.example.org
     </VirtualHost>

     <VirtualHost *:443>
     ServerName repos.example.org
     DocumentRoot /usr/local/www/repos.example.org
     SSLCertificateFile /usr/local/etc/ssl/certs/repos.example.org.crt
     SSLCertificateKeyFile /usr/local/etc/ssl/private/repos.example.org.pem
     </VirtualHost>
admin# cat /usr/local/etc/apache24/Includes/usr-local-repos-example.conf 
<Directory /usr/local/www/repos.example.org>
  Options Indexes FollowSymLinks
  DirectoryIndex index.html
  AllowOverride All
  Require all granted
</Directory>
admin# ll /usr/local/www/repos.example.org/test_001.git/
total 40
drwxr-x---  7 admin  www  512 Jul 22 12:36 ./
drwxr-x---  3 admin  www  512 Jul 22 12:36 ../
-rw-r-----  1 admin  www   23 Jul 22 12:36 HEAD
drwxr-x---  2 admin  www  512 Jul 22 12:36 branches/
-rw-r-----  1 admin  www   66 Jul 22 12:36 config
-rw-r-----  1 admin  www   73 Jul 22 12:36 description
drwxr-x---  2 admin  www  512 Jul 22 12:38 hooks/
drwxr-x---  2 admin  www  512 Jul 22 13:00 info/
drwxr-x---  7 admin  www  512 Jul 22 13:00 objects/
drwxr-x---  4 admin  www  512 Jul 22 12:36 refs/

Test the URL https://repos.example.org/test_001.git/ in a browser. You should see the content of the repo

Index of /test_001.git
Parent Directory
HEAD
branches/
config
description
hooks/
info/
objects/
refs/

Clone the repo locally on the server and commit something. This will also create the branch master. Then, you'll be able to clone the repo over https

shell> git clone https://repos.example.org/test_001.git
Cloning into 'test_001'...
0

Alternatively, the solution could be something simpler than the answers above:

  1. Go to the GitHub repo you want to clone

  2. 'Fork' the repo to your GitHub account

  3. Now, from your machine's CLI, do the "usual thing":

    $ git clone https://github.com/<your account>/<your fork> 
    

I found this to be necessary when recently trying to clone some repos at the raspberry pi GitHub site.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .