Skip to content

Database Projects – Committed to the wrong branch, now what?


In the past couple of months, I’ve been doing a lot of different things at the same time. Because of that, it is no exception that I have quite some branches for my Database Projects that I’m working on simultaneously.

Because of this, another issue arises as well, it happens now and then that I’m committing my changes to the wrong branch. Luckily for me, I’m making this mistake by committing directly to my development branch, where the change needs to be done in the end anyway.

Nevertheless, I need to get my change into my feature branch as well. In this data recipe, I will be guiding you through the process.


I have just created a feature/DWH-1 branch, where I have changed the Sales Reason Dimension. To get this change to my development branch, I’m checking out the development branch from the remote. Then I’m merging my feature/DWH-1 branch into my development branch.

I have 2 or 3 different branches available on our local machine. In my case: master, development, feature/DWH-1.

Screenshot from application » 1

At this point, I realized that I forgot to execute some development, which brings me to the moment to make the mistake. Instead of changing back to the feature branch on our development machine, I make the changes directly in the development branch and commit it.


To resolve the mistake I have made, we need to take a couple of actions. To get started, we need to figure out our unique commit-id.

To get this done, we can open up our Command Line Tool of preference and navigate to the location where your Database Project is saved on your local machine. (* see the tip at the end for an easy way to get to this folder location in Command Line). Once we get there, we can use the “git log” command to show all our commits. In my case, it shows something like:

Screenshot from application » 2

As you can see in the screenshot above, I highlighted the incorrect commit. We need to copy the commit-id to get this change in our feature branch without taking any other changes from the development branch. In my case “de8ae78db45ad8492a41320a0102b0b3628dbdd1”.

Now that we identified the git commit-id, we can switch to the branch where we want to add the commit. This can be done by using the git switch command.

Screenshot from application » 3

Now, it is time to add that particular git commit to the branch of our choice. We can easily copy commits by using a technique called cherry-picking. To execute this via Command Line, we need to execute the “git cherry-pick” command followed by the commit-id.

Screenshot from application » 4

As a last step, we need to clean up the branch where we made the incorrect commit. To do this, we switch back to the development branch and use the git revert command.

Screenshot from application » 5

As soon as we have executed all these steps, we have finished our recipe.

Cooking Tip

If you’re not familiar with Windows Command Prompt and you need to navigate to your GIT Repository folder on your local machine, you can execute the following steps as well to get to the right folder:

  1. Open your Visual Studio Database Project
  2. Navigate to the menu bar and choose GIT
  3. Choose the Open in Command Prompt option
Screenshot from application » 6

Published inAzure ReposDatabase ProjectsGeneral Post

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *