question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repository.Clone() : Cross host redirect not allowed

See original GitHub issue

Windows Server 2008 R2 SP2 ASP.NET C# libgit2sharp 0.21.0.176

From CLI this git operation succeeds without issue :

git clone https://www.github.com/{org-name}/{repo-name}.git

The expected local repo is created in folder \{org-name}\{repo-name}

But when ASP.NET C# app attempts programmatically equivalent operation LibGit2Sharp.Repository.Clone() of same GitHub URI an exception is thrown : “Cross host redirect not allowed”

In the Visual Studio debugger I can see that the URI is being formed and passed to Repository.Clone() as expected – so this isn’t an issue with a malformed URI.

C# code :

var cloneOptions = new CloneOptions { 
  BranchName = "master",
  Checkout = true,
  CredentialsProvider = (url, user, cred) =>    
  new UsernamePasswordCredentials { Username = {username}, Password = {password}}
};

string cloneResult;
try {
  cloneResult = Repository.Clone(
  "https://www.github.com/{my-org}/{my-repo}.git",
  "c:\github\{my-org}\{my-repo}",
  cloneOptions);            
} catch (LibGit2SharpException e) {}

Repository.Clone() throws a run-time exception :

Cross host redirect not allowed : at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)

Apparently here is where libgit2sharp throws the exception on line 188 : https://github.com/libgit2/libgit2/blob/master/src/netops.c

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
carlosmncommented, Aug 15, 2015

GitHub canonicalizes its URLs as https://github.com/{user}/{repo}(.git). You however keep using https://www.github.com/ as a URL, which is a hostname which GitHub itself never produces, and it will redirect away from the www regardless of whether you claim to be a Git or a browser.

As such, it counts as a cross-host redirect, since github.com and www.github.com are not the same hostname. If you remove that extraneous www. prefix, it should work.

0reactions
ethomsoncommented, Jun 22, 2018

@john-grandy-opentable I trust that things worked out in the end - I’m closing this, it’s quite stale now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to clone from Bitbucket cross host redirect not ...
Hi im having this error when I try to clone repository from Bitbucket. I am using v2020.10.7 studio. The whole error message is...
Read more >
libgit2sharp exception "cross host redirect not allowed"
I have various unit/integration tests that call the following code : var remote = Repository.Network.Remote.Add("origin","https://www.github.com ...
Read more >
How do I do cross-domain redirects to github repositories ...
The repository redirect blog post you linked to applies to internal redirects that GitHub does when a repository is renamed.
Read more >
Does git-clone support http redirects?
Hi everyone! I want to shorten the URL to a Github repo and use it for git clone. I tried bitly and Github's...
Read more >
Repository | GitLab
All projects can be cloned into Visual Studio Code from the GitLab user ... The redirects are available as long as the original...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found