无法克隆GitHub仓库:如何获取指定仓库的克隆URL?
Hey there,
The issue you're running into is that the URL you're trying to clone points to a specific subdirectory within a GitHub repository, not the repository itself. GitHub doesn't let you directly clone a single subdirectory—you need to either clone the entire repo first, or use a more advanced Git feature called sparse checkout if you only want that specific folder. Let's walk through both options:
Option 1: Clone the Entire Repository (Simplest Approach)
This is the easiest way if you don't mind downloading the full repo contents:
- First, grab the actual clone URL for the
aspnet/templatingrepo. On the repo's main GitHub page (just remove the/tree/dev/...part from your original URL), click the "Code" button in the top right corner, then copy either the HTTPS or SSH URL. The HTTPS one looks like this:https://github.com/aspnet/templating.git - Open your terminal or command prompt, run this command to clone the whole repo:
git clone https://github.com/aspnet/templating.git - Once cloning finishes, navigate into the repo folder:
cd templating - Switch to the
devbranch (since your target directory is under thedevbranch):git checkout dev - Finally, jump to the Angular-CSharp template directory you need:
cd src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/Angular-CSharp
Option 2: Sparse Checkout (Only Download the Target Directory)
If you want to save space and only get that specific subdirectory, use Git's sparse checkout feature:
- Create a new folder for your template and initialize an empty Git repo:
mkdir angular-csharp-template && cd angular-csharp-template git init - Enable sparse checkout in the repo:
git config core.sparseCheckout true - Tell Git which path you want to fetch:
echo "src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/Angular-CSharp/*" >> .git/info/sparse-checkout - Add the remote repository:
git remote add origin https://github.com/aspnet/templating.git - Pull the contents from the
devbranch:git pull origin dev
Either way, you'll end up with the Angular-CSharp template files you're looking for!
内容的提问来源于stack exchange,提问作者Unknown developer

