Getting "fatal: repository not found" when "git clone" a URL

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?


Solution 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.