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
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.
fatal: refusing to merge unrelated histories
git push -f
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
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.
git stash -u
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.