How to update shadcn/ui components without losing your changes
There is no update command: use add --dry-run and --diff to see changes, --overwrite to take them, and Git to put your own edits back.
- shadcn 4.23.0
- Tailwind CSS 4.3.5
- Vite 8
- React 19.3
There's no shadcn update command, because shadcn/ui components aren't a package. They're files in your repo. To update one, you ask the CLI for the latest version of that file and decide what to keep: npx shadcn@latest add button --diff shows what changed, and --overwrite replaces the file. With Git in between, you can take the update and keep your own edits.
We ran every command on this page in a shadcn 4.23 project where we had changed the button's corners to rounded-full.
1. See what would change
Start with a dry run. It lists which files would be created or overwritten and which dependencies would be added, and writes nothing:
npx shadcn@latest add button --dry-run┌ shadcn add button (dry run)│├ Files (1) ~1 overwrite│ ~ src/components/ui/button.tsx overwrite│⚠ 1 file will be overwritten.││ Run with --diff to view changes.└ Run without --dry-run to apply.Then the diff. Lines marked - are in your file now; lines marked + are what the registry has:
npx shadcn@latest add button --diff├ src/components/ui/button.tsx (overwrite)│ @@ -4,7 +4,7 @@│ - "group/button inline-flex shrink-0 items-center justify-center rounded-full border …│ + "group/button inline-flex shrink-0 items-center justify-center rounded-lg border …Two things to know when you read it. Your own edits show up as changes too, since the CLI compares with the registry's current file, not with the version you once installed. And formatting counts: in our diff, three lines differed only in quote style inside a class string ("size-" against 'size-'), with nothing real changed.
--diff and --view work for one file at a time. For many components, run add --all --dry-run first to see which files the registry would touch.
2. Update and keep your edits
Step 1: Commit first
Start with a clean working tree so the update is the only change Git sees.
Terminalgit add -A && git commit -m "Before shadcn update"Step 2: Overwrite the file
Terminalnpx shadcn@latest add button --overwrite --yes✔ Checking registry.ℹ Updated 1 file: - src/components/ui/button.tsxWithout
--overwritethe CLI asks before replacing an existing file, even with--yes;--yesonly skips the initial confirmation.Step 3: Review the change and put your edits back
git diffnow shows upstream's changes and the loss of your own, side by side. Usegit add -pto stage the hunks you want from upstream andgit checkout -pto bring your own lines back. For a small edit like ours, that's two keystrokes per hunk.Terminalgit diff --stat src/components/ui/button.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Dependencies get asked about too
When you add a component that depends on one you've edited, the CLI asks about the dependency. Adding dialog to our project (it uses button) stopped at:
npx shadcn@latest add dialog? The file button.tsx already exists. Would you like to overwrite? › (y/N)✔ Created 1 file: - src/components/ui/dialog.tsxℹ Skipped 1 file: (files might be identical, use --overwrite to overwrite) - src/components/ui/button.tsxAnswering no (the default) kept our edited button and still created the dialog. In CI or scripts, that prompt blocks, so pipe an answer in or decide up front with --overwrite.
Moving to a new style or theme
Changing the look of every component at once is a different job: npx shadcn@latest apply --preset <code> re-applies a preset and reinstalls your components in its style. --only theme limits it to the CSS variables. It overwrites the component files, so the commit-first routine above matters even more.
Components from other registries
The same commands work for any registry item: npx shadcn@latest add @themesdev/hero-12 --diff compares one of our blocks with your copy. Each UI Pro release is listed in the changelog, and --diff shows whether a block you installed has changed since. Installing from a registry covers the setup.
Questions
How do I update all shadcn components at once?
npx shadcn@latest add --all --overwrite reinstalls every component from the registry. It also adds the ones you never installed, so we prefer naming the components you use: add button card dialog --overwrite.
Is shadcn diff gone?
The old shadcn diff command still exists but prints a deprecation notice. Use add <component> --diff.
How do I know which shadcn version I'm on?
There's no version per component. npx shadcn@latest info shows your style, base library and preset, which decide what add gives you.
Related articles
- shadcn/uiInstall components from a shadcn registry (npx shadcn add @namespace)Install by URL with no setup, or name a registry in components.json and install by namespace. Private registries read their key from .env.local.
- Using themes.devInstall UI Pro blocks with the shadcn CLISet up the @themesdev registry once with an API key in .env.local, then install any block with one npx shadcn command. Free items need no key.
- shadcn/uiAdd a custom colour to a shadcn/ui themeThree places in your CSS: the value in :root, the dark value in .dark, and one line in @theme inline. Plus a brand button variant and a contrast check.
Still stuck? We answer every message ourselves. Write to us