39

I made a template sale website (gatsby / react). I cloned my template GitHub repo and changed the remote origin to a new private repo, pushing to which works fine.

I deploy to gh-pages with npm srcipt "deploy": "gatsby build --prefix-paths && gh-pages -d public" The first time I ran this command it seemed to stall so I control c'd out of it. Now, when I try to deploy I get the error "fatal: A branch named 'gh-pages' already exists."

git branch -a shows: remotes/origin/HEAD -> origin/master remotes/origin/gh-pages remotes/origin/master

But there is not a gh-pages branch on gitHub.

I tried rm -rf node_modules/gh-pages/.cache didn't work. Also, git push origin --delete gh-pages which gave "error: unable to delete 'gh-pages': remote ref does not exist".

I uninstalled and reinstalled gh-pages.

eoja
  • 1,642
  • 2
  • 12
  • 21
  • Is there more code I should show? – eoja Sep 19 '20 at 03:55
  • 1
    So you kept the .git directory from the initial clone? Have you looked into creating a github template? https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-template-repository then creating your new repo from the template? https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template – ksav Sep 19 '20 at 09:08
  • 2
    you may want to take a look at this https://stackoverflow.com/questions/35941566/git-says-remote-ref-does-not-exist-when-i-delete-remote-branch – Adam Tang Sep 19 '20 at 11:29
  • 1
    @ksav Thanks for the tip. I think I will make the original repo a template. – eoja Sep 19 '20 at 18:53
  • 1
    It is a timeout because Github is waiting to enter your credentials to authenticate you. Mostly it's a screen on your desktop that we don't see most of the time – Leketo Jun 25 '21 at 18:19
  • Not sure if it's relevant here, but in my case this appeared to be caused by switching to the local `gh-pages` branch when trying to run the `gh-pages` command. I switched back to `master` to fix the problem. – ggorlen Sep 01 '22 at 00:58

6 Answers6

102

I had to manually remove the folder node_modules/.cache/gh-pages to get the deployment to work.

Prior to this I had tried git fetch --prune, which removed remotes/origin/gh-page. I don't know if pruning the branches was a necessary step or not.

Shivang Kakkar
  • 421
  • 3
  • 15
eoja
  • 1,642
  • 2
  • 12
  • 21
  • 4
    I just `rm -rf node_modules/.cache/gh-pages` without `git fetch --prune` and it fixed the problem. – axiopisty Sep 02 '22 at 16:39
  • Thanks this worked! I just manually delete the `gh-pages` folder from `node_modules/.cache` from my editor (VSCode) – Bert Mar 02 '23 at 23:51
21

Just manually deleting the folder node_modules/.cache/gh-pages worked.

Shivang Kakkar
  • 421
  • 3
  • 15
KushalSeth
  • 3,265
  • 1
  • 26
  • 29
  • Please don't add "thank you" as an answer. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation), you will be able to [vote up questions and answers](https://stackoverflow.com/help/privileges/vote-up) that you found helpful. – Blastfurnace May 03 '21 at 15:02
18

On windows, you can run rm -rf node_modules/.cache/gh-pages. or manually go to the node_modules folder and delete the .cache/gh-pages.

Roninho
  • 336
  • 2
  • 7
1

delete gh-pages from node_modules/.cache then run :- npm run deploy after this your page is Successfully publish on gh page

abhirock74
  • 11
  • 2
0

if its instaled gllobaly it will be in this path: windows path will be : %USERPROFILE%\AppData\Roaming\npm\node_modules\gh-pages\.cache\<GITREPO>

just remove this Dir

A. El-zahaby
  • 1,130
  • 11
  • 32
-3

create new repository in git hub and follow the steps as usual then the game is over!