Let's say I have a website on GitHub Pages. Let's call that website MyFirstSite. Now, I am trying to create a new website inside of a new repository. That website is called MyNewSite. After adding and committing the files for MyNewSite, I attempted to push the changes to the gh-pages branch, but received this response:
To http://github.com/Jaklabs/MyFirstSite
! [rejected] gh-pages -> gh-pages (fetch first)
error: failed to push some refs to 'http://github.com/Jaklabs/MyFirstSite'
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.
It's as if it's trying to push the files to my other repository instead of the one I'm trying to work with. I'm rather new to Git. There's probably a very simple solution to this, but could someone point it out for me?
You can simply use:
git push --force
if you are sure that you don't have any unsynced file in the remote. Just as a precaution, download or clone the repo's file to another location before using the above command.
If you have any unsynced work then use git pull
before performing git push
and resolve any merge conflicts.
Your remote is not configured properly, try removing your old remote URL by-
git remote rm MyFirstSite
and add a new remote by
git remote add origin YOUR_REPO_URL
you can get YOUR_REPO_URL
from repo clone or download
button on github.
run git remote -v
,it should show something like git@github.com:USERNAME/REPO_NAME.git
Now, you can push your changes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.