decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

Failed to persist entry: API_ERROR: Branch not found

Open rahuldotbiz opened this issue 6 years ago • 11 comments

netlify-help **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.**

rahuldotbiz avatar Nov 09 '20 14:11 rahuldotbiz

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

tomrutgers avatar Nov 09 '20 15:11 tomrutgers

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.

j-o-o avatar Nov 15 '20 15:11 j-o-o

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.

rahuldotbiz avatar Nov 15 '20 15:11 rahuldotbiz

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.

j-o-o avatar Nov 15 '20 16:11 j-o-o

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

MoHassn avatar Nov 16 '20 20:11 MoHassn

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.

Wfritz5 avatar Nov 18 '20 21:11 Wfritz5

branch: main

This solution worked for me. Adding branch fixed the issue.

cleankoding-pradeep avatar Nov 30 '20 11:11 cleankoding-pradeep

Closing this issue resolved. Thanks everyone

erezrokah avatar Nov 30 '20 11:11 erezrokah

@MoHassn Is there any way to specify the branch name from a variable (i.e. process.env.BRANCH)

mudlabs avatar Jan 31 '21 03:01 mudlabs

@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 master as 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 means master doesn't exist, which leads to the this API error.

So we can either:

  • Add instruction in the doc to tell users to add branch: main to their config files, OR
  • Change something in the backend code of Netlify CMS to default to main instead of master.

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.

bytrangle avatar Aug 10 '21 08:08 bytrangle

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.

erezrokah avatar Aug 10 '21 08:08 erezrokah