Automate · Lesson 13 of 20

Keep your workspace in Git

Store collections as files next to your code, review them in pull requests and sync both ways without overwriting anyone.

Intermediate · 2 min · Updated

Your API tests change with your code, so they deserve the same history, branches and reviews. swc workspace pull writes a workspace as plain JSON files you can commit; swc workspace push saves your edits back. The files use the same layout as Export workspace in the app, so either side can read them.

Pull the workspace into your repository

Shell
swc login                       # once: paste an API key from Account → API keys
swc workspace pull api/ -w "Shop team"

You get:

Text
api/
  swastik.json              which collections and environments are in the folder
  collections/shop-api.json one readable file per collection
  environments/staging.json one per environment
  globals.json

Commit the folder. Secret values and current values are never written to these files, so they are safe to commit.

Change, review, push

  1. Edit the files, or keep working in the app and run swc workspace pull api/ again; files change only where something really changed, so diffs stay small.
  2. Open a pull request. Reviewers see exactly which requests, tests and variables changed.
  3. After the merge, save the files back to the workspace:
Shell
swc workspace status api/   # what would change, without saving
swc workspace push api/

No lost work

Both commands are careful about other people's changes:

  • push saves only files that changed, each against the version you pulled. If someone edited the same collection in the app since, push stops with a conflict instead of overwriting their work. Pull, merge, push again (or --force if you are sure).
  • pull never overwrites a file you edited and have not pushed. It keeps your file and tells you.
  • A secret left blank in a file keeps the value saved in the account.
  • push never deletes anything in the account.

Renaming a collection in the app keeps its file name, so Git shows an edit, not a delete and an add.

Run it from CI

A job on your main branch can keep the account up to date automatically:

Shell
SWC_API_KEY=${{ secrets.SWC_API_KEY }} swc workspace push api/

What you learned

  • swc workspace pull writes collections, environments and globals as reviewable JSON; push saves them back.
  • Conflicts are reported, unpushed edits are kept and secrets never reach the files.

Next: give front-end developers an API to build against before the real one exists.

Try it on your own API

Swastik Codes runs in the browser and is free to use. Create an account to send requests, sync your workspaces and invite your team.