How to fix a broken branch after a git merge or git rebase
This guide shows you how you can create a new branch with the original changes of your broken branch. Link to heading
Problems when merging or rebasing branches in a version control system like git can happen to anyone. I want to show you one way that works pretty good to resolve the issue. Of course, there are other ways like reverting the rebase and doing it again, but I like this approach more.
Relevant git commands Link to heading
▶ git cherry-pick
▶ git log
▶ git checkout
▶ git branch
1 Create a new branch from the merge/rebase target Link to heading
Let’s assume you wanted to rebase the main branch onto your dev branch and something went wrong because the application does launch anymore.
So you create a new branch dev2 from the main branch as the first step. That means you have all the latest changes from main already in your branch and you don’t need to rebase anymore.
2 Apply the changes from the broken branch to the new branch Link to heading
The next step is to apply all your changes from dev to dev2. Switch to your dev2 branch and get all commits with the git cherry-pick <id> command.
To find the commit ids, you can use the git log command on the dev branch (see image below). Apply the changes in chronological order. In the end, you have a branch with all of your changes and also the changes of the rebase source.

Git log with commit ids
3 Push the new branch Link to heading
Finally, push the dev2 branch. You might need to set the upstream, but git will assist you with that.
4 Delete the broken branch Link to heading
The original dev branch is useless now. You can delete it in your local repository as well as in the remote repository.
Conclusion Link to heading
I showed you a strategy to fix problems with a broken branch by replacing it with a working one. It’s a simple and straightforward approach and might help you in the future.
Related articles Link to heading

How to configure Visual Studio to enable git rebase Link to heading
Visual Studio doesn’t support the git rebase workflow by default. I’ll show you the required settings that need to be changed.

Can’t use your pipeline in Azure DevOps with .NET7? Here is a solution! Link to heading
After upgrading your app to a newer .NET version the cloud build agent of Azure DevOps fails. Here is what you can do against it!

Here is a Collection of Useful Tips for Visual Studio Link to heading
With these tips, you can increase your productivity in Visual Studio 2022 by a lot!