fatal: A branch named 'gh-pages' already exists
Asked Answered
V

6

46

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.

Vinic answered 19/9, 2020 at 1:58 Comment(6)
Is there more code I should show?Vinic
So you kept the .git directory from the initial clone? Have you looked into creating a github template? docs.github.com/en/github/… then creating your new repo from the template? docs.github.com/en/github/…Collyrium
you may want to take a look at this #35942066Connective
@Collyrium Thanks for the tip. I think I will make the original repo a template.Vinic
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 timeSupertax
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.Nepean
V
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.

Vinic answered 19/9, 2020 at 18:52 Comment(4)
I just rm -rf node_modules/.cache/gh-pages without git fetch --prune and it fixed the problem.Garrygarson
Thanks this worked! I just manually delete the gh-pages folder from node_modules/.cache from my editor (VSCode)Farahfarand
You can also add that rm command to your predeploy script to save having to manually run it every time. "predeploy": "rm -rf node_modules/.cache/gh-pages && npm run build",Inadvertent
Yes this fixed the problem for me. I removed the remote branch gh-pages too, no prune needed.Benny
R
24

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

Roselba answered 3/5, 2021 at 0:53 Comment(1)
Please don't add "thank you" as an answer. Once you have sufficient reputation, you will be able to vote up questions and answers that you found helpful.Pew
P
19

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.

Prate answered 20/4, 2021 at 8:3 Comment(0)
A
1

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

Adermin answered 17/7, 2022 at 16:40 Comment(0)
Q
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

Quietism answered 19/6, 2023 at 8:47 Comment(0)
B
-3

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

Breakfast answered 11/12, 2022 at 6:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.