<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Switching Branches using code in notebooks? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/switching-branches-using-code-in-notebooks/m-p/149637#M53142</link>
    <description>&lt;DIV&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I’m working on a project in a Databricks notebook and I’m trying to implement the following workflow:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a new branch from Python code&lt;/LI&gt;&lt;LI&gt;In the next cell, switch the notebook to that newly created branch&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I’m able to create the branch without issues, but attempting to switch to it results in errors. Has anyone implemented something similar or found a reliable method to handle the branch switch from within a notebook?&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 02 Mar 2026 17:39:28 GMT</pubDate>
    <dc:creator>damirg</dc:creator>
    <dc:date>2026-03-02T17:39:28Z</dc:date>
    <item>
      <title>Switching Branches using code in notebooks?</title>
      <link>https://community.databricks.com/t5/data-engineering/switching-branches-using-code-in-notebooks/m-p/149637#M53142</link>
      <description>&lt;DIV&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I’m working on a project in a Databricks notebook and I’m trying to implement the following workflow:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a new branch from Python code&lt;/LI&gt;&lt;LI&gt;In the next cell, switch the notebook to that newly created branch&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I’m able to create the branch without issues, but attempting to switch to it results in errors. Has anyone implemented something similar or found a reliable method to handle the branch switch from within a notebook?&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 02 Mar 2026 17:39:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/switching-branches-using-code-in-notebooks/m-p/149637#M53142</guid>
      <dc:creator>damirg</dc:creator>
      <dc:date>2026-03-02T17:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Branches using code in notebooks?</title>
      <link>https://community.databricks.com/t5/data-engineering/switching-branches-using-code-in-notebooks/m-p/149654#M53148</link>
      <description>&lt;P&gt;Curious . What are you trying to achive with this setup ? I can imagine u are able to create a branch because that command could be running on the remote server . But switching to a new branch needs to happen on the local server. Is this case its a a notebook cell . But why would you want to do this in the first place.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2026 04:21:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/switching-branches-using-code-in-notebooks/m-p/149654#M53148</guid>
      <dc:creator>pradeep_singh</dc:creator>
      <dc:date>2026-03-03T04:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Branches using code in notebooks?</title>
      <link>https://community.databricks.com/t5/data-engineering/switching-branches-using-code-in-notebooks/m-p/149717#M53160</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/201653"&gt;@damirg&lt;/a&gt;&amp;nbsp;same question what&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/202980"&gt;@pradeep_singh&lt;/a&gt;&amp;nbsp;has but if you still want to proceed with this way then try out this:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;NOTE:: 1) Rename the attach file extension to .py&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;2) change SSS to your foldername within databricks workspace/Repos/&amp;lt;&amp;lt;foldername&amp;gt;&amp;gt;/&amp;lt;&amp;lt;reponame&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;See if you can use this to change your branch, This has more methods but use what you need&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Pseudocode below (modify just for your usecase):&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; repo_url&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;repo_name&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;branch_name&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;get_repo_info&lt;/SPAN&gt;&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;repo_config&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;get_repo_config&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;repo_name&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;branch_name&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;repo_url&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;json&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;dumps&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;repo_config&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;indent&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;repo_exists&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;get_existing_repo&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;databricks_url&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;databricks_token&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;repo_name&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;json&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;dumps&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;repo_exists&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;indent&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt; &lt;SPAN&gt;repo_exists&lt;/SPAN&gt; &lt;SPAN&gt;else&lt;/SPAN&gt; &lt;SPAN&gt;"Repo does not exist"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt; &lt;SPAN&gt;repo_exists&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gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;update_repo&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;databricks_url&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;databricks_token&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;repo_id&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;repo_config&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;f&lt;/SPAN&gt;&lt;SPAN&gt;"Repository &lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;repo_name&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt; updated."&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;else&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;create_workspace_directory&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;databricks_workspace_url&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;databricks_token&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/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&gt; created."&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2026 16:33:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/switching-branches-using-code-in-notebooks/m-p/149717#M53160</guid>
      <dc:creator>saurabh18cs</dc:creator>
      <dc:date>2026-03-03T16:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Branches using code in notebooks?</title>
      <link>https://community.databricks.com/t5/data-engineering/switching-branches-using-code-in-notebooks/m-p/150089#M53236</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Great question! Yes, you can switch Git branches programmatically in Databricks -- there are a few approaches depending on your use case.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;OPTION 1: DATABRICKS PYTHON SDK (RECOMMENDED FOR NOTEBOOKS)&lt;/P&gt;
&lt;P&gt;The simplest approach from within a notebook is using the Databricks Python SDK, which is pre-installed on Databricks clusters. You can use the ReposAPI.update() method to switch branches:&lt;/P&gt;
&lt;P&gt;from databricks.sdk import WorkspaceClient&lt;/P&gt;
&lt;P&gt;w = WorkspaceClient()&lt;/P&gt;
&lt;P&gt;# First, find your repo by path&lt;BR /&gt;repos = list(w.repos.list(path_prefix="/Repos/your_username/your_repo_name"))&lt;BR /&gt;repo = repos[0]&lt;/P&gt;
&lt;P&gt;print(f"Current branch: {repo.branch}")&lt;BR /&gt;print(f"Repo ID: {repo.id}")&lt;/P&gt;
&lt;P&gt;# Switch to a different branch&lt;BR /&gt;w.repos.update(repo_id=repo.id, branch="my-feature-branch")&lt;/P&gt;
&lt;P&gt;print("Branch switched successfully!")&lt;/P&gt;
&lt;P&gt;You can also switch to a specific tag instead of a branch:&lt;/P&gt;
&lt;P&gt;w.repos.update(repo_id=repo.id, tag="v1.0.0")&lt;/P&gt;
&lt;P&gt;Docs: &lt;A href="https://databricks-sdk-py.readthedocs.io/en/latest/workspace/workspace/repos.html" target="_blank"&gt;https://databricks-sdk-py.readthedocs.io/en/latest/workspace/workspace/repos.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;OPTION 2: REST API VIA REQUESTS&lt;/P&gt;
&lt;P&gt;If you prefer using the REST API directly, you can call the PATCH /api/2.0/repos/{repo_id} endpoint:&lt;/P&gt;
&lt;P&gt;import requests&lt;/P&gt;
&lt;P&gt;# Get your workspace URL and token from notebook context&lt;BR /&gt;workspace_url = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiUrl().getOrElse(None)&lt;BR /&gt;token = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().getOrElse(None)&lt;/P&gt;
&lt;P&gt;headers = {&lt;BR /&gt;"Authorization": f"Bearer {token}",&lt;BR /&gt;"Content-Type": "application/json"&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;# Step 1: Find your repo ID&lt;BR /&gt;response = requests.get(&lt;BR /&gt;f"{workspace_url}/api/2.0/repos",&lt;BR /&gt;headers=headers,&lt;BR /&gt;params={"path_prefix": "/Repos/your_username/your_repo_name"}&lt;BR /&gt;)&lt;BR /&gt;repo_id = response.json()["repos"][0]["id"]&lt;/P&gt;
&lt;P&gt;# Step 2: Switch branch&lt;BR /&gt;response = requests.patch(&lt;BR /&gt;f"{workspace_url}/api/2.0/repos/{repo_id}",&lt;BR /&gt;headers=headers,&lt;BR /&gt;json={"branch": "my-feature-branch"}&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;print(response.json())&lt;/P&gt;
&lt;P&gt;Docs: &lt;A href="https://docs.databricks.com/api/workspace/repos/update" target="_blank"&gt;https://docs.databricks.com/api/workspace/repos/update&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;OPTION 3: DATABRICKS CLI&lt;/P&gt;
&lt;P&gt;If you are automating from outside a notebook (e.g., CI/CD pipelines):&lt;/P&gt;
&lt;P&gt;# Switch to a branch&lt;BR /&gt;databricks repos update --repo-id &amp;lt;repo-id&amp;gt; --branch my-feature-branch&lt;/P&gt;
&lt;P&gt;# Find your repo ID first&lt;BR /&gt;databricks repos list --path-prefix /Repos/your_username/your_repo_name&lt;/P&gt;
&lt;P&gt;Docs: &lt;A href="https://docs.databricks.com/dev-tools/cli/repos-cli.html" target="_blank"&gt;https://docs.databricks.com/dev-tools/cli/repos-cli.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;IMPORTANT CAVEATS&lt;/P&gt;
&lt;P&gt;1. Notebook state is lost -- Switching branches that alter notebook source code will clear cell outputs, comments, version history, and widgets.&lt;/P&gt;
&lt;P&gt;2. Uncommitted changes carry over -- If you have uncommitted changes on the current branch, they will carry over to the new branch unless they conflict with code on the target branch.&lt;/P&gt;
&lt;P&gt;3. Don't switch while jobs are running -- If a job is executing notebooks from a Git folder and you switch branches mid-run, some notebooks may reflect the old branch while others reflect the new one.&lt;/P&gt;
&lt;P&gt;4. Repos API not supported with CLI-enabled Git folders -- If your Git folder has "Git CLI access" enabled (beta), the Repos API is not supported. You would need to use git checkout commands directly in a web terminal instead.&lt;/P&gt;
&lt;P&gt;5. Switching branches on a repo you're currently running in -- Be careful if the notebook calling w.repos.update() is itself inside the repo you're switching. The notebook code in memory will continue to run, but any subsequent %run calls or file reads will pull from the new branch.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;BEST PRACTICE: SEPARATE REPOS PER BRANCH&lt;/P&gt;
&lt;P&gt;The recommended Databricks workflow is for each developer to have their own Git folder mapped to the same remote repository, working in their own development branch. Rather than switching branches in a single repo, consider cloning the repo to a different path for each branch you need:&lt;/P&gt;
&lt;P&gt;w.repos.create(&lt;BR /&gt;url="&lt;A href="https://github.com/your-org/your-repo.git" target="_blank"&gt;https://github.com/your-org/your-repo.git&lt;/A&gt;",&lt;BR /&gt;provider="gitHub",&lt;BR /&gt;path="/Repos/your_username/your_repo_feature_branch"&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;This avoids the state-loss issues that come with branch switching.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DOCUMENTATION REFERENCES&lt;/P&gt;
&lt;P&gt;- Git integration for Databricks Git folders: &lt;A href="https://docs.databricks.com/repos/" target="_blank"&gt;https://docs.databricks.com/repos/&lt;/A&gt;&lt;BR /&gt;- Git operations with Git folders: &lt;A href="https://docs.databricks.com/repos/git-operations-with-repos.html" target="_blank"&gt;https://docs.databricks.com/repos/git-operations-with-repos.html&lt;/A&gt;&lt;BR /&gt;- Repos REST API: &lt;A href="https://docs.databricks.com/api/workspace/repos" target="_blank"&gt;https://docs.databricks.com/api/workspace/repos&lt;/A&gt;&lt;BR /&gt;- Databricks SDK for Python - ReposAPI: &lt;A href="https://databricks-sdk-py.readthedocs.io/en/latest/workspace/workspace/repos.html" target="_blank"&gt;https://databricks-sdk-py.readthedocs.io/en/latest/workspace/workspace/repos.html&lt;/A&gt;&lt;BR /&gt;- Git folders limitations: &lt;A href="https://docs.databricks.com/en/repos/limits.html" target="_blank"&gt;https://docs.databricks.com/en/repos/limits.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Hope this helps! Let me know if you have any follow-up questions.&lt;/P&gt;
&lt;P&gt;* This reply used an agent system I built to research and draft this response based on the wide set of documentation I have available and previous memory. I personally review the draft for any obvious issues and for monitoring system reliability and update it when I detect any drift, but there is still a small chance that something is inaccurate, especially if you are experimenting with brand new features.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2026 20:17:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/switching-branches-using-code-in-notebooks/m-p/150089#M53236</guid>
      <dc:creator>SteveOstrowski</dc:creator>
      <dc:date>2026-03-07T20:17:46Z</dc:date>
    </item>
  </channel>
</rss>

