This error occurs when you try to perform an operation on a remote named 'upstream' that doesn't exist in your Git repository. You need to add the upstream remote before using it, typically when working with a forked repository.
The "fatal: No such remote 'upstream'" error indicates that Git cannot find a remote repository with the name "upstream" in your local repository's configuration. This usually happens when you're working with a forked repository and trying to sync changes from the original repository. When you fork a repository on GitHub, GitLab, or Bitbucket, your fork only has one remote configured by default: "origin" (pointing to your fork). The "upstream" remote is a conventional name used to reference the original repository that you forked from, but it must be manually added. This error commonly appears when: - Following a tutorial that assumes upstream is already configured - Running `git fetch upstream` or `git pull upstream main` on a fork - Trying to sync your fork with the original repository - Copying commands from documentation without setting up the remote first
First, see what remotes are currently configured in your repository:
git remote -vTypical output for a fork (before adding upstream):
origin [email protected]:YOUR-USERNAME/REPO.git (fetch)
origin [email protected]:YOUR-USERNAME/REPO.git (push)If you only see "origin", that's your fork. You need to add "upstream" to reference the original repository.
If you see no remotes at all:
# Your repository has no remotes configured
git remote -v
# (no output)This means you need to add both origin and upstream.
Add the original repository as the upstream remote:
git remote add upstream https://github.com/ORIGINAL-OWNER/ORIGINAL-REPO.gitFor SSH (if you have SSH keys configured):
git remote add upstream [email protected]:ORIGINAL-OWNER/ORIGINAL-REPO.gitExamples:
# If you forked facebook/react
git remote add upstream https://github.com/facebook/react.git
# If you forked microsoft/vscode
git remote add upstream https://github.com/microsoft/vscode.gitWhere to find the original repository URL:
1. Go to your fork on GitHub/GitLab/Bitbucket
2. Look for "forked from ORIGINAL-OWNER/ORIGINAL-REPO" below the repository name
3. Click on that link to go to the original repository
4. Copy its URL from the address bar or the "Code" button
Confirm that upstream is now configured:
git remote -vExpected output after adding upstream:
origin [email protected]:YOUR-USERNAME/REPO.git (fetch)
origin [email protected]:YOUR-USERNAME/REPO.git (push)
upstream https://github.com/ORIGINAL-OWNER/REPO.git (fetch)
upstream https://github.com/ORIGINAL-OWNER/REPO.git (push)You should now see both "origin" (your fork) and "upstream" (the original repository).
Now you can fetch updates from the original repository:
git fetch upstreamExpected output:
remote: Enumerating objects: 50, done.
remote: Counting objects: 100% (50/50), done.
remote: Compressing objects: 100% (25/25), done.
Unpacking objects: 100% (50/50), done.
From github.com:ORIGINAL-OWNER/REPO
* [new branch] main -> upstream/main
* [new branch] develop -> upstream/developThis downloads the latest commits from upstream without merging them into your local branches.
To update your local branch with changes from upstream:
# Switch to your main branch
git checkout main
# Merge upstream changes into your local main
git merge upstream/main
# Push the updates to your fork (origin)
git push origin mainAlternative: Rebase instead of merge (cleaner history):
git checkout main
git rebase upstream/main
git push origin main --force-with-leaseNote: Use --force-with-lease instead of --force for safer force-pushing that won't overwrite others' changes.
If the upstream remote exists but has the wrong URL, update it:
# Check current URL
git remote get-url upstream
# Update to correct URL
git remote set-url upstream https://github.com/CORRECT-OWNER/CORRECT-REPO.gitCommon mistakes to check:
- Repository was renamed or moved to a different organization
- Typo in the owner or repository name
- Using HTTP instead of HTTPS or SSH
- The original repository was deleted
If there are issues with the upstream configuration, remove it and add it fresh:
# Remove the problematic upstream remote
git remote remove upstream
# Add it again with the correct URL
git remote add upstream https://github.com/ORIGINAL-OWNER/ORIGINAL-REPO.git
# Verify the configuration
git remote -vThis is useful when:
- The URL was set incorrectly
- You need to switch between HTTPS and SSH
- The remote configuration is corrupted
Understanding Git Remotes:
Git remotes are named references to remote repositories. By convention:
- origin: Points to your own repository (typically your fork)
- upstream: Points to the original repository you forked from
These names are conventions, not requirements. You could use any name, but following conventions makes it easier for others to understand your setup.
Working with Multiple Remotes:
You can have many remotes configured:
git remote add upstream https://github.com/original/repo.git
git remote add colleague https://github.com/colleague/repo.git
git remote add backup [email protected]:user/repo.gitGitHub CLI Shortcut:
If you're using GitHub CLI, you can set up remotes more easily:
# Clone your fork and automatically set up upstream
gh repo fork ORIGINAL-OWNER/REPO --clone
# Or, if you already cloned, sync with upstream
gh repo syncListing Remote Branches:
After adding upstream, see what branches are available:
# List all remote branches
git branch -r
# List only upstream branches
git branch -r | grep upstreamKeeping Fork Updated Regularly:
Set up a script or alias for regular syncing:
# Add to ~/.bashrc or ~/.zshrc
alias sync-fork='git fetch upstream && git checkout main && git merge upstream/main && git push origin main'GitHub's "Fetch upstream" Button:
On GitHub, you can also sync your fork through the web interface:
1. Go to your fork on GitHub
2. Click "Fetch upstream" (or "Sync fork") above the file list
3. Click "Fetch and merge"
This updates the default branch on GitHub without using the command line.
warning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server