Duplicating a Stackbit site is a manual process. The steps below will be sufficient for the average site. You may need to adjust based on your individual requirements.
The Process
In general the process looks like this:
- Create a new site
- Transfer the repo to your GitHub account
- Locally duplicate the existing project
- Commit and push
1. Create a New Site
The first step is the easy part — create a new Stackbit project. Select any theme.
The generated code will eventually be replaced, so it doesn't matter where you start.
2. Transfer Repo Ownership
After you're new site is up and running with Stackbit, transfer the code to your GitHub account. This will create a new repo with the new site's code.
3. Replace New Site Code
Next, you'll want to replace the new repo's code with your existing code. This can be done a number of ways. What we've provided here is the safer method.
Clone the New Site
First, clone the new site — the one that Stackbit just transferred to your GitHub account. Your new project will have a default branch (main
) and a preview
branch, which is the branch used by the Stackbit application. Check out your preview
branch.
git clone [EXISTING_GITHUB_REPO_URL]
cd [REPO_NAME]
git checkout preview
Delete Everything!
Now, the fun part! Delete every file in your repo. And commit the change. (Don't push yet!)
git add .
git commit -m "Delete everything!"
Replace with Existing Site Code
Next, add into your project all the code from your existing site. Commit the changes to the preview
branch.
git add .
git commit -m "Duplicate existing site"
4. Update Stackbit
Now that your code looks good locally, you can update Stackbit by pushing.
Push to preview
Push these two commits to the preview
branch.
git push
Stackbit now needs to check and install new dependencies and restart your preview server. It can take some time for the changes you pushed to be reflected in Stackbit.
Publish Live Site
When everything looks good in Stackbit, that means your preview
branch is in good shape and you're ready to go. You're ready to publish. Doing so will merge your preview
branch into main
and update your live site.
Since you already have the code locally, you're also welcome to merge preview
into main
manually and push main
to GitHub. This will automatically trigger a redeploy of your site.