Last Updated
Viewed 682,612 Times
  

I have a repository in Git. I made a branch, then did some changes both to the master and to the branch.

Then, tens of commits later, I realized the branch is in much better state than the master, so I want the branch to "become" the master and disregard the changes on master.

I cannot merge it, because I don't want to keep the changes on master. What should I do?

Extra: In this case, the 'old' master has already been push-ed to another repository such as GitHub. How does this change things?

Similar Question 1 : make git branch the master branch

My master branch is so different than my development branch that I would like it to just become my master branch without having to do a merge, is this possible? Seems like I could walk into a lot of work if I just try and do a merge.

Let's say I made the most recent commit and pushed it to the my private repository, how do you go back to the branch you want to checkout and then push it to the head/master of the repository??

git checkout branch_name

and what command do I have to do to move that branch_name to the master/head ?

I am in a kind of limbo. I had one branch named Branch_A along with the master branch which were exactly the same. I was supposed to make new branch Branch_B and commit/push every thing on that branch. Unfortunately, I committed every thing on master branch. I have one local branch Branch_B where are all file were committed. I was supposed to commit all those on Branch_B remotely but I did it in master branch. Now I want to do the following:

  1. Make remote Branch_A the master branch and keep remote Branch_A as it is
  2. Make remote branch B and push the commits from local branch B there.

What is the best way to achieve this?

Similar Question 4 (3 solutions) : shortcut for git merging master into current branch

Similar Question 5 (2 solutions) : I want to reset my current Git branch to master branch

cc