1

I have two branches master (which is very old) and new.

What I want to achieve is basically to make new branch to be master.

I tried to merge, but without success. The result of the merge was still not master branch became identical to new branch.

I tried to rebase, but also without success, it was telling me, that I have some deleted files and couldn't rebase. In the end I deleted all deleted files from tracking, but still the result of rebasing was somehow wrong.

user1685095
  • 5,787
  • 9
  • 51
  • 100
  • do you want to clone your one head to be the master? or are you attempting to solve the conflicts between the old code and the new and have a merged copy? – Mike Feb 18 '14 at 17:57
  • I want just one branch, the new one and I want it to be renamed to master. – user1685095 Feb 18 '14 at 17:58
  • [Duplicate of this question<---------](http://stackoverflow.com/questions/2763006/change-the-current-branch-to-master-in-git) – Mike Feb 18 '14 at 18:02

2 Answers2

1

I would recommend performing a merge using the "ours" strategy. Doing this will allow you to pull in the history of master, while effectively disregarded everything else. The end result is that the new master, will look exactly what your current branch looks like.

A step by step would look something like:

git checkout goodBranch
git merge master -s ours
git checkout master
git merge goodBranch
Peter Foti
  • 5,526
  • 6
  • 34
  • 47
1

It sounds like you just want to rename the branches:

git branch -m master old   # rename master to old
git branch -m new master   # rename new to master

After this, if you want to clean up the remote too, accordingly:

git push origin old        # backup of the old master
git push origin master -f  # need to force, history changed
git push origin :new       # delete "new", which is now master
janos
  • 120,954
  • 29
  • 226
  • 236
  • This solution will only really work if their are no remote branches, if there are then the process of renaming is a bit more complex. – Peter Foti Feb 18 '14 at 21:06
  • I guess you're right, it's worth mentioning, so I added a note for that. – janos Feb 18 '14 at 21:17