What's Actually Happening
Git remote repository not found occurs when Git cannot access the remote repository. This happens due to incorrect URLs, authentication failures, deleted repositories, or access permission issues.
The Error You'll See
Push error:
```bash $ git push origin main
remote: Repository not found. fatal: repository 'https://github.com/user/repo.git' not found ```
Fetch error:
```bash $ git fetch origin
fatal: repository 'https://github.com/user/repo.git/' not found ```
Clone error:
```bash $ git clone https://github.com/user/repo.git
fatal: repository 'https://github.com/user/repo.git/' not found ```
Authentication error:
```bash $ git push
fatal: Authentication failed for 'https://github.com/user/repo.git/' fatal: Repository not found. ```
Why This Happens
- 1.Wrong URL - Remote URL incorrect or typo
- 2.Repository deleted - Remote repository removed
- 3.No access - Repository private, user lacks permission
- 4.Authentication failed - Wrong credentials
- 5.Organization changed - Repo moved or renamed
- 6.Network unreachable - Remote server not accessible
Step 1: Check Remote URL
```bash # List all remotes git remote -v
# Show specific remote git remote show origin
# Get remote URL git config --get remote.origin.url
# Check if URL is correct # Common URL formats: # HTTPS: https://github.com/user/repo.git # SSH: git@github.com:user/repo.git # Git protocol: git://github.com/user/repo.git
# Verify repository exists in browser # Open the URL in browser # Should show repository page
# If URL incorrect, update it git remote set-url origin https://github.com/user/correct-repo.git ```
Step 2: Fix Remote URL
```bash # Update remote URL git remote set-url origin https://github.com/user/new-repo.git
# Change from HTTPS to SSH git remote set-url origin git@github.com:user/repo.git
# Change from SSH to HTTPS git remote set-url origin https://github.com/user/repo.git
# Add new remote git remote add upstream https://github.com/original/repo.git
# Remove wrong remote git remote remove wrong-origin
# Rename remote git remote rename old-name new-name
# Verify new URL git remote -v ```
Step 3: Check Repository Exists
```bash # Test if repository accessible curl -I https://github.com/user/repo.git # 200 OK = exists # 404 = not found
# For private repos, test with auth curl -I -u username:token https://github.com/user/private-repo.git
# Check GitHub API curl https://api.github.com/repos/user/repo # Returns repo details if exists
# For GitLab curl https://gitlab.com/api/v4/projects/user%2Frepo
# For Bitbucket curl https://api.bitbucket.org/2.0/repositories/user/repo
# Visit repository in browser # If deleted, you'll see 404 page ```
Step 4: Check Authentication
```bash # For HTTPS remotes, check credentials
# Using credential helper git config --get credential.helper
# Test authentication git ls-remote origin # If auth fails, prompts for credentials
# For GitHub, use personal access token # Create token: Settings > Developer settings > Personal access tokens
# Use token as password git clone https://github.com/user/repo.git Username: your-username Password: ghp_xxxxxxxx (token)
# Store credentials git config credential.helper store
# Or use manager git config --global credential.helper manager
# For SSH, check key ssh -T git@github.com # Should show: Hi username! You've successfully authenticated
# Check SSH key loaded ssh-add -l
# Add SSH key ssh-add ~/.ssh/id_rsa ```
Step 5: Fix SSH Authentication
```bash # Test SSH connection to GitHub ssh -T git@github.com
# If connection refused: # SSH key not configured
# Generate SSH key ssh-keygen -t ed25519 -C "your@email.com"
# Or RSA (older) ssh-keygen -t rsa -b 4096 -C "your@email.com"
# Add key to SSH agent eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
# Copy public key cat ~/.ssh/id_ed25519.pub
# Add to GitHub: Settings > SSH and GPG keys > New SSH key
# Test connection again ssh -T git@github.com
# For GitLab ssh -T git@gitlab.com
# For Bitbucket ssh -T git@bitbucket.org ```
Step 6: Fix HTTPS Authentication
```bash # For HTTPS remotes without proper auth
# Use credential helper to cache credentials git config --global credential.helper cache # Cache for 15 minutes
# Cache for longer git config --global credential.helper 'cache --timeout=3600' # Cache for 1 hour
# Store permanently (less secure) git config --global credential.helper store
# Use personal access token instead of password # GitHub: Settings > Developer settings > Personal access tokens
# Clone with token in URL (not recommended for security) git clone https://token@github.com/user/repo.git
# Better: Use credential helper with token git clone https://github.com/user/repo.git # Enter username and token as password
# For GitLab # Settings > Access tokens git clone https://oauth2:token@gitlab.com/user/repo.git
# For Bitbucket # Settings > App passwords git clone https://username:app-password@bitbucket.org/user/repo.git ```
Step 7: Check Access Permissions
```bash # Repository may exist but you lack access
# For GitHub # Check your organizations curl -H "Authorization: token ghp_xxx" https://api.github.com/user/orgs
# Check repository permissions curl -H "Authorization: token ghp_xxx" https://api.github.com/repos/org/repo
# For organization repos: # - Must be organization member # - Or have direct access granted
# Request access from repository owner # Or fork the repository
# Fork public repo gh repo fork user/repo
# Clone your fork git clone https://github.com/your-username/repo.git
# Add original as upstream git remote add upstream https://github.com/user/repo.git ```
Step 8: Handle Renamed/Moved Repository
```bash # Repository renamed or moved to different organization
# Check old URL redirects curl -I https://github.com/old-org/old-name # May show redirect to new URL
# GitHub creates redirects for renamed repos # Git may follow redirect automatically
# If redirect fails, update remote URL git remote set-url origin https://github.com/new-org/new-name.git
# Check for GitHub notification # GitHub shows "This repository has moved"
# For local repos, update origin git remote set-url origin new-url
# Verify fetch works git fetch origin ```
Step 9: Fix Network Connectivity
```bash # Check if remote server reachable
# Test basic connectivity ping github.com
# Test HTTPS port nc -zv github.com 443
# Test SSH port nc -zv github.com 22
# Check DNS resolution nslookup github.com
# Check corporate firewall/proxy # May block git protocol
# Use HTTPS instead of git:// git remote set-url origin https://github.com/user/repo.git
# Configure proxy if needed git config --global http.proxy http://proxy:8080
# For SSH through proxy # ~/.ssh/config Host github.com ProxyCommand nc -X 5 -x proxy:8080 %h %p ```
Step 10: Recreate Repository Access
```bash # If repository access completely lost
# Option 1: Clone fresh git clone https://github.com/user/repo.git
# Option 2: Re-add remote to existing repo git remote remove origin git remote add origin https://github.com/user/repo.git git fetch origin
# Option 3: Create new remote # If you have local repo but remote deleted # Create new repository on GitHub/GitLab # Push to new remote
git remote set-url origin https://github.com/user/new-repo.git git push -u origin main
# Option 4: Mirror local repo git remote set-url --push origin https://github.com/user/new-repo.git git push origin --mirror ```
Remote URL Formats Reference
| Protocol | Format | Auth Method |
|---|---|---|
| HTTPS | https://host/user/repo.git | Username + token |
| SSH | git@host:user/repo.git | SSH key |
| Git | git://host/user/repo.git | No auth (deprecated) |
| Local | /path/to/repo.git | None |
| File | file:///path/to/repo.git | None |
Verify the Fix
```bash # After fixing remote URL or authentication
# 1. Verify remote URL git remote -v # URL should be correct
# 2. Test fetch git fetch origin # Should succeed without error
# 3. Test push git push origin main # Should push successfully
# 4. Check remote details git remote show origin # Should show remote branch info
# 5. List remote branches git branch -r # Should show remote branches
# 6. Test SSH connection (if using SSH) ssh -T git@github.com # Should show authentication success
# 7. Verify credentials stored git config --get credential.helper # Should show helper configured ```
Related Issues
- [Fix Git Push Permission Denied](/articles/fix-git-push-permission-denied)
- [Fix Git Authentication Failed](/articles/fix-git-authentication-failed)
- [Fix Git Remote Ref Updated](/articles/fix-git-remote-ref-updated)