Connecting a new repo to a new Sanity project without building a new Sanity app

3 replies
Last updated: Jun 5, 2023
Hey! I currently have a Next.js site connected to Sanity, all living within an NX mono-repo. I need to create a new separate website with the same Sanity schemas, so I forked my repo. Now, I need to connect this new repo to a new Sanity Project. The current options to create a new Sanity Project are through the CLI or using a starter build, but I don't want to generate a new local Sanity repo since the repo I forked already has a Sanity app. Is there a way to create a new Project in Sanity without having to build a new Sanity app? I just need a new Project instance to connect to.
AI Update

Good news! You can absolutely create a new Sanity project without running sanity init or generating new local files. Since you already have your schemas and Studio configuration from your forked repo, you just need to create a new project instance and point your existing code to it.

Create a New Project via manage.sanity.io

The simplest way is to create a new project directly through manage.sanity.io:

  1. Go to manage.sanity.io in your browser
  2. Look for a "New project" or "Create project" button
  3. Fill in your project details (name, organization, plan, etc.)
  4. Once created, you'll get a new project ID

You can also access this interface from the command line without initializing a new project:

npx sanity@latest manage

This opens the management interface where you can create projects through the web UI.

Connect Your Forked Repo to the New Project

After creating the project, update your forked repo's configuration files:

1. Update sanity.cli.js (or .ts)

import { defineCliConfig } from "sanity/cli";

export default defineCliConfig({
  api: {
    projectId: "<your-new-project-id>", // Change this
    dataset: "production",
  }
});

2. Update your Studio config (sanity.config.js or .ts)

import { defineConfig } from 'sanity'

export default defineConfig({
  projectId: '<your-new-project-id>', // Change this
  dataset: 'production',
  // ... rest of your existing config
})

3. Update environment variables

If you're using environment variables in your Next.js app (like NEXT_PUBLIC_SANITY_PROJECT_ID), update those in your .env files:

NEXT_PUBLIC_SANITY_PROJECT_ID=your-new-project-id
NEXT_PUBLIC_SANITY_DATASET=production

Create Your Dataset

Don't forget to create the dataset for your new project. You can do this:

  • Through manage.sanity.io in your project settings
  • Or using the CLI: sanity dataset create production

Since you're working in an NX monorepo with existing schemas, this approach lets you reuse all your Studio configuration and schema definitions while pointing to a completely separate Sanity project instance. No need to scaffold any new files!

If you delete the
sanity.config
and
sanity.cli
files, then run
sanity init
will it initialize a new project using the existing schemas? It used to work this way in V2 and I think we may have recently added it back in.
I think
sanity init --reconfigure
was recently added.
Thank you
user M
and
user A
!! I think I've got it connected to the new Sanity project. I just inherited this project so I appreciate the help. πŸ™πŸ™ŒπŸ’―

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?