1

I recently created a github repo that was empty, and I got stuck in a loop of repeating error messages that don't seem to have a resolution with the suggested messages offered by git.

I add a file:

git add filename
git commit -m "commit message"
git push origin master

Which gives me the following message:

Updates were rejected because the tip of your current branch is behind.
its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.

So I try:

fatal: refusing to merge unrelated histories

Then I try:

git push -f

Which gives me:

fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

git push --set-upstream origin master

But if I try that I get:

error: failed to push some refs to 'https://github.com/JonathanBechtel/cdc-  
dashboard.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

If I try git stash -u I'm told that I have no files to stash.

Does anyone have an explanation for this repeating loop of error messages?

Jonathan Bechtel
  • 3,497
  • 4
  • 43
  • 73
  • As a significant side note, the ultimate problem here is that you *did not* create an *empty* repository on GitHub. GitHub has two different ways to create a repository: one leaves it empty and the other creates an initial README.md file and commits that. You used the second method, so your Git had a different initial commit from theirs. (Merging with the "allow unrelated histories" flag is an easy way to handle the problem, or you could force-push to discard the GitHub initial commit.) – torek Nov 28 '16 at 13:12

2 Answers2

1

Use this:

git pull origin master --allow-unrelated-histories

Then your git push should succeed:

git push origin master

As this SO article discusses, you may be getting the unrelated histories error during the first pull because your local branch appears as new and having nothing in common with the history of the remote branch.

Community
  • 1
  • 1
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

Your local master branch is behind from remote master branch. Update local before push.

$ git pull origin master          # update local master
$ git push origin master          # push the changes
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73