I'm very new at programming and was wondering if you could replace a develop branche in Git (VSTS) with a new develop branche? I'm asking this because I did merges that messed up the branche and am not able to reset and delete it the hard way. So maybe deleting the whole branche would be easier. Thank you
Asked
Active
Viewed 57 times
-1
-
Have a look at [this](https://stackoverflow.com/questions/2862590/how-to-replace-master-branch-in-git-entirely-from-another-branch) SO question. – Jeroen Heier Sep 03 '18 at 14:59
1 Answers
0
If rewriting history of this branch is an available option (i.e. if you're alone working on that branch), just set your branch tip wherever you want :
Let's assume you located the "good" commit in your log (the point where you would like your branch to be at) and stored its hash <goodCommitHash>
. Then just do
git branch -f <yourBranchName> <goodCommitHash>
git push -f origin <yourBranchName>
Then again, DO NOT choose this solution if other users share this branch and might have pulled from it. Or at least, not until you agree with them on the best course of action.
(Basic assumptions)
- your remote is called
origin
, like in most places (but in theory it might be anything) - before trying anything you did a backup of the present situation just in case (
git checkout <yourBranchName>; git branch <backupBranch>
) - if you happened to have uncommitted changes in your work directory before trying this fix, you thought of stashing or committing them

Romain Valeri
- 19,645
- 3
- 36
- 61
-
Thanks! It solved my problem, but I'm going to delete this question as it is marked as duplicate. Thank you for your time – Sparkleypie Sep 04 '18 at 08:45
-
1
-