Scenario: create an empty warehouse in gitee and push the existing warehouse. Through
remote add origin < git path>
specified warehouse, error message:error: failed to push some refs to ' https://gitee.com/XXXX/XXXXX.git '
Terminal Information:
JerrydeMacBook-Pro:web-h5 jerrylam$ git push
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
After executing git push --set-upstream origin master
, it reports another error, as follows .
JerrydeMacBook-Pro:web-h5 jerrylam$ git push --set-upstream origin master
To https://gitee.com/XXXX/web.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/XXXX/web.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Try git pull origin master
, the error message is as follows
JerrydeMacBook-Pro:web-h5 jerrylam$ git pull origin master
From https://gitee.com/XXXX/web.git
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
Solutions
# Change the previous git pull origin master to the following code
git pull origin master --allow-unrelated-histories
Finally, we can push it
JerrydeMacBook-Pro:web-h5 jerrylam$ git push origin master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 3.77 KiB | 3.77 MiB/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Powered by Gitee.com
To https://gitee.com/XXXX/web.git
f6b4cf0..c538ad9 master -> master
When push
doesn’t go up, first git pull
ensures the latest code
git pull --allow-unrelated-histories
# Or specify branches
git pull origin master --allow-unrelated-histories
Similar Posts:
- Git Pull Error: Please specify which branch you want to merge with.
- [Solved] Git pull fatal: refusing to merge unrelated histories
- Git push Updates were rejected because the tip of your current branch is behind
- How to Solve error: failed to push some refs to ‘xxxx’
- [Solved] error: failed to push some refs to ‘xxxx’
- error: src refspec master does not match any [How to Solve]
- Git Push hint: Updates were rejected because the remote contains work that you do hint: not have …
- git pull There is no tracking information for the current branch.
- Git Status Warming: Your branch is ahead of ‘origin/master’ by 1 commit…