Search code examples
gitgithub-pages

'fatal: Couldn't find remote ref refs/heads/gh-pages' after running:git push origin :gh-pages


My gh-pages didn't update correctly so I decided to remove the old version and push new copy. Some steps I took:

1 I found how to remove gh-pages here:

https://webapps.stackexchange.com/questions/8512/how-to-remove-github-pages

2 Then I run git push origin :gh-pages Gh-pages was successfully deleted.

3 Next step I ran: git push origin gh-pages I got :

'fatal: Couldn't find remote ref refs/heads/gh-pages' 

4 Tried to create a gh-pages locally then push again. Only show README.md.

5 Tried to npm rm -rf node_modules/gh-pages/ && npm install from https://github.com/tschaub/gh-pages/issues/17

But the problem still there, the same fatal error.

Extra step: I also configured my publishing source settings-> "GitHub Pages"->'Master', but it didn't seem to work.

https://docs.github.com/en/github/working-with-github-pages/creating-a-github-pages-site#creating-your-site

Did I do something wrong? The gh-pages was successfully created once no drama by running "npm run deploy" before. So I don't understand what's wrong. Any idea will be much appreciated.


Solution

  • I finanlly figured out a way to re-publish the gh-pages, that's

    git push origin :gh-pages
    

    next step, in the local branches, build another branch named: gh-pages then current branch points to gh-pages, run git push -u origin gh-pages. (Here I also ran npm run build first to build the build folder locally, and it reminded to run npm run deploy as scripted in package.json file.)

    After last few steps it didn't show fatal: Couldn't find remote ref refs/heads/gh-pages again.

    However, this may only display the README.md,even in the setting the source already pointed to the gh-pages, so I switched between the master and gh-pages branches ,even tried the /doc and /(root) folder, and one of it finanlly worked.