Failed to persist entry: API_ERROR: Branch not found
**I recently start a blog using gatsby starter. The problem i'm facing right now is, whenever i post a blog via netlify CMS it shows Failed to persist entry: API_ERROR: Branch not found need help on this.**
Is your repo part of an organization? In that case you might have to approve your app: https://help.github.com/en/articles/requesting-organization-approval-for-oauth-apps
I too have encountered this issue. I even re-did the gatsby tutorial, remade all repos and acces tokens, but it still throws this error.
I'll update if I find the solution.
I too was facing the same issue and currently facing but i tried to figure it out. My website is hosted on Netlify so i went to the netlify initial url that is rahulism.netlify.app/admin and i have accessed it but when i go to rahulism.co/admin i face the same error. We'll this is just a small work, working for me.
I changed
backend:
name: github
repo: your-username/your-repo-name
to
backend:
name: git-gateway
branch: main
And it's working. Look at your repo branch and compare it to the branch in your config.yml.
In config.yml file, specify your main branch name (main or master or any other name) in the backend like below and it should work
backend:
name: github
repo: username/repo-name
branch: branch-name
Thanks MoHassn. My branch name is main, adding in that 'branch:main' fixed the problem. I did not have to switch the name from github to git-gateway.
branch: main
This solution worked for me. Adding branch fixed the issue.
Closing this issue resolved. Thanks everyone
@MoHassn Is there any way to specify the branch name from a variable (i.e. process.env.BRANCH)
@erezrokah Do you consider this to be an unexpected behavior? I haven't looked at the source code, but my guess is:
- If users don't specify branch name in the config file, Netlify CMS will set
masteras the default branch to which all CMS commits and PRs are made. - However, currently, when a new repo is initiated, its default branch will be
main, which meansmasterdoesn't exist, which leads to the this API error.
So we can either:
- Add instruction in the doc to tell users to add
branch: mainto their config files, OR - Change something in the backend code of Netlify CMS to default to
maininstead ofmaster.
Someone else has done the first option, but I'm leaning towards the second one because Netlify CMS always needs a default branch to push content to.
Hi @bytrangle,
Someone else has done the first option, but I'm leaning towards the second one because Netlify CMS always needs a default branch to push content to.
:100: To this.
There's an ongoing discussion about it, see here.
I'm not sure if anyone started working on it though, so if you'd like to pick that one up, comment on the issue to make sure.