public static string GetRemoteName(string completeName, IEnumerable<string> remotes) { string trimmedName = completeName.StartsWith("refs/remotes/") ? completeName.Substring(13) : completeName; foreach (string remote in remotes) { if (trimmedName.StartsWith(string.Concat(remote, "/"))) return remote; } return string.Empty; }