This Git error occurs when you try to push to a remote repository that has no common references with your local repository. It typically happens when pushing to an empty remote or when using git push without specifying a branch.
When Git displays "No refs in common and none specified; doing nothing", it means the push operation cannot proceed because Git cannot find any matching branches between your local repository and the remote. By default, Git's push behavior (called "matching") tries to push all local branches that have corresponding branches on the remote. When the remote repository is empty or has no branches that match your local ones, Git finds nothing to push and gives up. This is Git's way of saying: "I don't know what you want me to push, and I couldn't figure it out automatically either." The error often appears after cloning an empty repository, adding files, and then trying to push without explicitly specifying which branch to push.
Specify the branch you want to push explicitly. This is the most common solution:
# If your branch is named main
git push -u origin main
# If your branch is named master
git push -u origin masterThe -u flag sets the upstream tracking, so future pushes will work with just git push.
Verify what your local branch is actually called:
git branchThe current branch will be marked with an asterisk (*). Make sure you're pushing the correct branch name. Modern Git defaults to "main", but older setups may use "master".
If your repository has no commits, there is nothing to push. Create an initial commit first:
git add .
git commit -m "Initial commit"
git push -u origin mainYou cannot push an empty repository - Git needs at least one commit to create a branch reference.
If you're unsure of your branch name, push HEAD directly:
git push origin HEAD:mainThis explicitly pushes your current HEAD to the remote branch called "main", regardless of what your local branch is named.
Set Git to automatically push the current branch:
git config --global push.default currentWith this setting, git push will push your current branch to a remote branch of the same name, creating it if necessary. Other options include:
- simple (default in Git 2.x): Push current branch to its upstream
- upstream: Push current branch to its upstream branch
- matching: Push all matching branches (legacy default)
### Understanding push.default modes
Git has several push behavior modes that affect what happens when you run git push without arguments:
- nothing: Produces an error; you must always specify what to push
- current: Push the current branch to a same-named branch on the remote
- upstream: Push the current branch to its configured upstream
- simple: Like upstream, but refuses if the upstream branch name differs (safest, default since Git 2.0)
- matching: Push all local branches that have matching remote branches (pre-2.0 default)
The "no refs in common" error often occurs with the old "matching" default when the remote is empty.
### Checking remote repository state
To verify what the remote repository contains:
git ls-remote originAn empty result confirms the remote has no branches yet. You must push with an explicit branch name to create the first reference.
### Branch name conventions
GitHub, GitLab, and other platforms have shifted from "master" to "main" as the default branch name. When creating remote repositories, check what default branch name the platform expects and match your local branch accordingly:
# Rename your local branch if needed
git branch -m master main
git push -u origin mainwarning: 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