DEV Community

Devin Shoemaker
Devin Shoemaker

Posted on

2

Change Nx Default Affected Branch to Main

The Nx affected commands are a powerful way to scale monorepos by only rebuilding and retested the apps and libraries that could be affected by a particular change. This is accomplished by comparing hashes of the files modified in the current branch compared to the base branch which defaults to master. It's easy to pass in a different branch as a parameter with --base, however, you can also change this default in the workspace nx.json.

First, make sure that you have created the new base branch. In this example, we will be using main as our base branch.

Next, edit the workspace nx.json. If you do not have the affected property then you will need to add that first, and then you can customize the base branch.

{
  "npmScope": "nxtend",
  "affected": {
    "defaultBase": "main"
  },
  ...
}
Enter fullscreen mode Exit fullscreen mode

Lastly, this feature is only available in Nx 9.5 or higher. If you are currently on a version of Nx lower than this then I recommend upgrading to the latest version of Nx, or at least the latest version of Nx 9.

Upgrade to latest version:

nx migrate latest
Enter fullscreen mode Exit fullscreen mode

Upgrade to Nx 9.7:

nx migrate @nrwl/workspace@9.7.0
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay