30

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,222
  • 1
  • 7
  • 18
  • 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

3 Answers3

73

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.

Stark Programmer
  • 181
  • 1
  • 13
eoja
  • 1,222
  • 1
  • 7
  • 18
17

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

Stark Programmer
  • 181
  • 1
  • 13
KushalSeth
  • 1,901
  • 1
  • 15
  • 25
  • 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
16

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
  • 306
  • 2
  • 6