Question

fatal: A branch named 'gh-pages' already exists

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.

 46  39955  46
1 Jan 1970

Solution

 115

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.

2020-09-19

Solution

 24

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

2021-05-03