No refs in common and none specified; doing nothing

GitGitolite

Git Problem Overview


I had a local git project that I wanted to add to gitolite. Apparently this is hard so I abandoned the idea. I created a new gitolite repo by adding it to gitolite-admin/conf/gitolite.conf and committing and pushing the changes. Then I cloned the new repo with git clone git-noah:project-name successfully. I then copied all files and folders except .git to the project-name folder. I did,

git add -A
git commit -a -m "Moved to new repo."
git push

I get this error:

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'git-noah:project-name'

Git Solutions


Solution 1 - Git

No "main" exists yet on the remote (origin) repository.

git push origin main

After this first push you can use the simpler

git push

Edit: With the recent trends my answer has been update to replace "master" with "main"

Solution 2 - Git

If you are receiving error:

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch.

But not receiving error:

warning: push.default is unset

Make sure you have run git commit before attempting to run git push

Solution 3 - Git

If you're using git to mirror then use this :

git config remote.backup.mirror true

Solution 4 - Git

your master branch might be upstream and needs to be unset On branch master

Your branch is based on 'origin/master', but the upstream is gone. (use git branch --unset-upstream to fix)

Solution 5 - Git

Taking up the comment of this user below the accepted answer.

I had the error in question when moving from an hg Mercurial repo to a GitLab repo using fast-export when the GitLab repository was already created some time ago by and still empty.

The reason for the error was that this empty frame of the new GitLab repo was already built with the setting that the main branch should be called "master". This is also what the message hints at: Perhaps you should specify a branch such as 'master'.

In your case, you likely hat a migration tool that switched the branch name to main by default. In my case, I had added the parameter -M -main to the fast-export command to change the name to the nowadays more common main - which then clashes with the needed master in the already setup GitLab repository.

Being in the git-repo folder, I ran (WRONG!):

/data/fast-export/hg-fast-export.sh -r /data/hg-repo -A /data/authors --force -M -main

Therefore, I went back to the start and tried it again without that -M -main: I deleted the .git folder in the git-repo folder, ran git init my_git_repo again, then ran the fast-export command just without -M -main. Then everything worked: I could git checkout HEAD, git remote add origin [email protected]:my_project-url.git, git branch, git push -u origin --all and git push -u origin --tags.

Solution 6 - Git

Your local and remote repositories do not share the same history, since you recreated the repo. Therefore, Git won't let you push this content.

If you are not afraid of losing the content that is on the remote repository, you can force push : git push -f.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNoahView Question on Stackoverflow
Solution 1 - GitOliverView Answer on Stackoverflow
Solution 2 - GitpirateofebayView Answer on Stackoverflow
Solution 3 - GitStrugglerView Answer on Stackoverflow
Solution 4 - GitHimanshuView Answer on Stackoverflow
Solution 5 - Gitquestionto42standswithUkraineView Answer on Stackoverflow
Solution 6 - GitMartinView Answer on Stackoverflow