I have some unwanted commits in master branch, I've made a branch say, new_branch from previous commit. Now new_branch Looks better than master, I'd like to change new_branch as my master branch How can I do it?
Asked
Active
Viewed 105 times
0
Sathish Manohar
- 5,859
- 10
- 37
- 47
3 Answers
2
Locally, you can do
git checkout new_branch
git branch -D master
git checkout -b master
If master has been pushed somewhere, you can now do
git push --force WHEREVER master
But watch out, since this will require everyone who pulled the previous master to perform Git black magic to get the new master.
If master has been published, then it's better to just git revert the bad commits.
Fred Foo
- 355,277
- 75
- 744
- 836
1
You can do:
git branch -m master oldmaster
git branch -m new_branch master
Note that you will have to use force push if you have pushed elsewhere.
manojlds
- 290,304
- 63
- 469
- 417
0
Assuming you haven't published master yet:
git reset --hard 'id of the last good commit in master'to throw away the commits in mastergit merge --ff-only new_branchto apply the commits fromnew_branchto master.
ThiefMaster
- 310,957
- 84
- 592
- 636
-
2Wouldn't just `git reset --hard new_branch` be better? – svick Nov 01 '11 at 15:49