Gherkin Studio keeps the Gherkin scenarios on a Jira story in step with a .feature file in GitHub, GitLab.com or Bitbucket Cloud. It works both ways, and it never overwrites text a person hasn't seen. The function that decides what to do is 32 lines long. This article is about everything that went wrong around those 32 lines before the app was listed.
Updated on 2 December 2026.
Sunday, 25 October: the test is green and wrong
My sync tests were all passing. One of them covered the classic race: I read a file from Bitbucket, somebody else pushes, then I try to write. Bitbucket has to refuse. In my test it did, with a 409, because 409 means Conflict and that's what a sensible API sends.
There was one problem. I had written that Bitbucket myself. It was a fake, a few lines of test code, and it agreed with me because I was its author.
So that Sunday I tried the real one. I put a throwaway file called probe.txt in a test repository and sent it a stale write on purpose. Real Bitbucket refused too, and left the file alone. But it answered 400, with this text: "The parent commit specified (…) is not the head of branch main."
My app had never heard that sentence. A user would have seen "Saving the file failed with HTTP 400" where the conflict screen should be. Nothing lost, but no clue what to do next.
I sent the same stale write to GitHub and GitLab that day. Their answers are further down. First, the easy part.
Three texts, not two
Compare what Jira has with what Git has and you learn that they differ. You don't learn who changed. So the app keeps a third text: what both sides had after the last successful sync. I call it the base.
With a base, the decision fits in a table:
| Jira, since the base | Git, since the base | The sync |
|---|---|---|
| unchanged | unchanged | does nothing |
| changed | unchanged | writes Jira's text to Git |
| unchanged | changed | brings Git's text into Jira |
| changed | changed | stops and asks a person |
| unchanged | file deleted | stops and asks a person |
| changed | file deleted | stops and asks a person |
| emptied | unchanged | stops and asks a person |
On a first sync there is no base. If only one side has text, that side wins. If both have text and it differs, the app asks.
This is the middle of the function. local is Jira, remote is Git:
const localChanged = !sameContent(local, base);
const remoteChanged = !sameContent(remote, base);
if (!localChanged && remoteChanged) return { action: 'pull', content: remote };
if (localChanged && !remoteChanged) {
if (localEmpty) {
return { action: 'conflict', local, remote, base,
reason: 'All scenarios were removed in Jira; confirm before emptying the Git file' };
}
return { action: 'push', content: local };
}
if (!localChanged && !remoteChanged) return { action: 'none', content: remote };
return { action: 'conflict', local, remote, base,
reason: 'Both Jira and Git changed since the last sync' };
The rows that say "asks a person" are the ones where I was tempted to be clever:
- The file was deleted in Git. That doesn't delete the scenarios in Jira. The person chooses: create the file again, or clear Jira.
- Somebody emptied the editor in Jira. That doesn't empty the file in Git. Select-all, delete, save is a thing fingers do on their own.
- Only the line endings differ. CRLF against LF, or spaces at the end of a line, are not a change. Otherwise a colleague's editor settings start a conflict on a file nobody edited.
There's no automatic merge. When both sides changed, you get a diff, line by line, and three buttons: keep Jira's version, keep Git's, or use what's in the editor after you merged by hand. A badly merged test scenario still parses and still runs. It tests something nobody wrote, and it's green.
And nothing syncs until somebody clicks Sync with Git on the story. No background sync, no Git webhooks. The sync can't write into a story while somebody is typing in it, because between two clicks it does nothing at all.
Three hosts, three ways to say "too late"
Between my read and my write, somebody can push. Each host lets you say "write this only if the file is still the one I read". Each has its own field for it, and its own way to refuse. This is what I got in October 2026:
| Host | What you send with the write | What a stale write gets back |
|---|---|---|
| GitHub |
sha of the file you read |
409. An existing file and no sha at all: 422 |
| GitLab.com | last_commit_id |
400, "You are attempting to update a file that has changed since you started editing it." |
| Bitbucket Cloud |
parents, the commit you expect at the head of the branch |
400, "The parent commit specified (…) is not the head of branch main." |
GitLab deserves its own paragraph. It answers 400 to a stale write, and 400 to every other bad request. The only difference is the English sentence in the body. So my conflict detection on GitLab is a regular expression that looks for "changed since" and "already exists". Every other 400 stays an error. I'm not proud of it. I also don't know a better way.
Bitbucket has a different gap: no version for a single file. GitHub gives you a blob SHA. GitLab gives you the last commit that touched the file. Bitbucket gives you the branch.
My first design took that literally and used the head of the branch as the file's version. Any commit to any other file moves the head. So the next sync would have shouted "conflict" about a file nobody had touched. Now the version is a SHA-256 of the content. Right before a write, the app reads the file again at the head, compares, and sends that head as parents.
A short window is still there. A commit to another file that lands inside it shows up as a conflict. The person sees that Git's text is the same as before, keeps Jira's version and moves on. I can live with that.
404 is HTTP shrugging
A 404 on a file can mean the file is gone. It can also mean the branch is gone, or that the token can't see the repository any more. GitHub answers 404 for a repository your token has no access to, which is discreet and not much help.
My code read every 404 as "the file was deleted in Git" and offered a button to clear the scenarios in Jira. Somebody deletes a branch, somebody else trusts the message, and a story's scenarios are gone.
Now a 404 on the file leads to a second question: is the branch there? If it isn't, a third: is the repository there? Only then does the message name what's missing.
The repository check had a bug of its own when I first wrote it. If that last request hit a busy host (429 or 5xx), the app announced "repository not found". Same mistake, one floor up. Now it says the request failed, which is all it knows.
Three bugs that never met a real repository
A code review found these before the code ran against anything real. That's the cheapest place to find a bug, and the least glamorous.
The base from another repository. An admin points the project at a different repository. The app still holds the base from the old one. On the next sync Jira looks unchanged and Git looks changed, so the app pulls the new repository's file over the story without asking. The fix: the sync state carries a short hash of provider, repository, branch and folder. If it doesn't match the settings, the story counts as never synced, and two different texts are a conflict.
The token that would have gone to the wrong host. An admin switches the provider from GitHub to GitLab and leaves the token field empty, which normally means "keep the one you have". The app would then send the stored GitHub token to GitLab's API. This one isn't funny. A stored token is now reused only for the provider it was saved for.
The conflict screen is a race too. A person can look at a diff for ten minutes. Meanwhile Git can move again, and so can Jira. So when they choose, the app sends back the Git version and the Jira revision they were shown. If either has moved, nothing is written and they see the new state. The two "keep" buttons also switch off once somebody types in the editor during a conflict, because pressing one would throw that typing away.
One more from the same screen, found earlier, while building it. Choosing "keep Git's version" would have written Git's own text back to Git: a commit that changes nothing, left in somebody's history like a business card. The resolve step now reads Git first and writes only if the text differs.
The story that moved house
Each story syncs to a file named after its key, like features/SCRUM-1.feature. Move the story to another project and Jira gives it a new key. I found out on my test site what happens next: the sync created MOVE-4.feature right beside the old file. Both carried the same tag, so CI would run every scenario twice.
The tidy fix is to delete the old file. I didn't do it. The app never deletes a file in someone's repository, and I'd like to keep saying that sentence without footnotes. So the scenarios follow the story to its new key, and a notice on the story names the old file. A person removes it.
What I'd do again
- Keep the decision a pure function of three strings. No network, no storage, and every row of the table is a one-line test.
- Send a stale write to each real host before believing a fake of it. A fake holds my guesses about the host. Until I've tried the real one, the test is checking the guess.
- Treat "not found" as "I don't know yet" until a second request says what is missing.
- Store where the base came from, next to the base.
- When the code can't tell, stop and show both versions. The question costs somebody a minute. The silent overwrite costs them work, and they find out later, if at all.
Short answers
Why not merge the two versions automatically?
Because a wrong merge of a test scenario still runs. The app shows a diff and a person decides.
Which HTTP status means "somebody pushed before you"?
It depends on the host. In October 2026 I got 409 from GitHub, and 400 from GitLab.com and Bitbucket Cloud, each with its own message.
Can a deleted branch look like a deleted file?
Yes. Both answer 404 on the file. Ask for the branch, then for the repository, before you tell anyone a file is gone.
Does the sync run in the background?
No. It runs when somebody clicks the button, and at no other time.
Does the app ever delete files in the repository?
No. After a story moves, it names the old file and leaves the deleting to a person.
The first article in this series is about Forge itself: eight things I learned building on Atlassian Forge. The same sync, seen from the user's side, is in Keep .feature files in Jira and Git in sync.
I built Gherkin Studio, the app in this article. You can find it on the Atlassian Marketplace.
Top comments (0)