dbt-labs / dbt-labs/dbt

[FEAT] dbt Extension should auto-detect git branch to generate the right schema name during invocation

Open
#14,047 1 comment 0 reactions 0 assignees View on GitHub
area:vscode AX engine:v2 status:triage type:feature
Dominant language
Rust
Stars
13.8k
Forks
2.6k
Avg merge
21h 31m
Merged PRs (30d)
56

Description

**Is your feature request related to a problem? Please describe.**

I'm always frustrated when I have to manually update environment variables in my MCP configuration every time I switch Git branches. Currently, I need to maintain a VS Code task that runs a Python script to read the current Git branch and write it to both `.vscode/settings.json` and `.vscode/mcp.json` files. This workaround is cumbersome and error-prone, especially when frequently switching between branches during development.

This is particularly important because the branch name is used to generate the correct schema and database names in `dev` builds. Without this variable being properly set to match the current branch, the extension may compile models pointing to the wrong development environment, leading to confusion and potential data issues.

**Is your feature request related to a particular component of the dbt Fusion Engine**
- [ ] CLI Features
- [ ] Adapter or Database Driver Features
- [ ] SQL Understanding Features
- [x] VS Code extension

**Describe the solution you'd like**

I would like the VS Code extension to automatically detect the current Git branch and make it available as a dynamic variable for builds/invocations and also the MCP server configuration. Specifically:

1. The extension should detect when the Git branch changes (either through VS Code's Git extension events or by polling)
2. Automatically inject the current branch name as an environment variable to the extension and MCP server without requiring manual file updates

For example, instead of manually setting:
```json
"env": {
"BRANCH": "dd-1"
}
```

It would just know what branch I'm on and either write it to an env file or perhaps just read direct from my `.zshrc` file where I can set up something like:

```sh
export BRANCH=$(git branch --current-branch)
```

And the extension would automatically resolve this to the current branch name when branches are switched.

**Describe alternatives you've considered**

Current workaround: A VS Code task that runs a Python script to update the configuration files manually. This requires remembering to run the task after every branch switch.

**Additional context**

My current task configuration looks like this:
```json
{
"label": "Update BRANCH in settings",
"type": "shell",
"command": "python3 -c \"import json, subprocess; branch = subprocess.check_output(['git', 'branch', '--show-current'], text=True).strip(); settings_path = '.vscode/settings.json'; settings = json.load(open(settings_path)); settings.setdefault('dbt.environmentVariables', {})['BRANCH'] = branch; json.dump(settings, open(settings_path, 'w'), indent=4); mcp_path = '.vscode/mcp.json'; mcp = json.load(open(mcp_path)); mcp['servers']['dbt']['env']['BRANCH'] = branch; json.dump(mcp, open(mcp_path, 'w'), indent=2)\""
}
```

This feature would significantly improve the developer experience for projects that use branch-specific configurations, which is common in environments with multiple development slices or branch-based data isolation strategies. By ensuring the branch variable is always synchronized with the actual Git branch, developers can be confident that the dbt extension is generating SQL with the correct target schemas and databases for their development environment.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.