0

I have a master branch which I always used for pushes, somehow anyday I could not push because of mismatching code and I started a new Branch B1. So I pushed at this B1 for months. But this is not a very good solution.

So I want, that the master branch will hold exact the same coding which I currently have in my Netbeans.

I don´t want to merge, because there are errors while merging. I just want exactly the same code in the master branch as it is now in my Netbeans. Or maybe I can merge both and end up with exact the same code as I have now in Netbeans.

Any ideas how to do that?

enter image description here

enter image description here

user2784676
  • 105
  • 1
  • 12
  • So... your branch `B1` is the new master? Merge it back into master then. – Shark Oct 27 '16 at 10:59
  • 2
    Just merge B1 with your master branch. There will probably be merge conflicts but I'm sure you can solve them. – Prad Oct 27 '16 at 11:00
  • 1
    Possible duplicate of [Change the current branch to master in git](http://stackoverflow.com/questions/2763006/change-the-current-branch-to-master-in-git) – Joe Oct 27 '16 at 11:12
  • Mergıng impossible, I need to do somethıng manually, but how? – user2784676 Oct 27 '16 at 11:16
  • I mean I guess you could checkout your B1 branch, copy the code. Then switch to master branch and paste it. Also, I don't really know what you mean by merging impossible. Your image just shows a merge conflict, you solve the conflicts and everything will be fine. – Prad Oct 27 '16 at 11:19
  • 1
    @Prad When you're copying code from one branch to the other to resolve conflicts, you're almost certainly not properly using git. – Joost Oct 27 '16 at 11:22
  • @Joost Yeah, this is exactly what I am thinking. But I don't really understand why the merging is impossible. – Prad Oct 27 '16 at 11:29
  • 1
    @Prad if two branches have diverged for months, surely the conflicts are going to be so numerous that there's no point in trying to merge them, making it virtually impossible. Just choosing one and checking it out as `master` makes more sense, as @kabanus suggests below. – Joost Oct 27 '16 at 11:33

2 Answers2

1

If you just want the branch pointer of 'master' to move to where b1 is, and forget what you had before (I would create a backup branch where master is in any case!):

git checkout master
git reset --hard b1

To create a backup branch, before reset:

git checkout -B master_bak

then checkout master again and reset.

kabanus
  • 24,623
  • 6
  • 41
  • 74
  • I am not a pro but, here you backup the master and then reset b1. How it comes that b1 is going to be the new master. And shouldn´t I backup b1 before reset? – user2784676 Oct 27 '16 at 12:15
  • Not sure what you;re asking. Branches are just pointer to commits. After you reset master to b1, both would point to the same commit. If you checkout master or b1 you would get the exact same code. On the other hand, if no other branch is pointing to the old master commit, once you 'move the pointer', any commits dangling there will be removed. After you reset master to b1, you should probably delete b1. – kabanus Oct 27 '16 at 12:36
  • It doesn´t worked for me, after doing that I had only the past state of the master branch :( However, before I did that I copied my whole project directory, I end up deleting my repo and push my local git history to a new repo. Now it works and I have also all of my commits. I am happy :) – user2784676 Oct 27 '16 at 13:06
0

As an alternative to resetting the branch, which can sometimes have conflicts of it's own if the working directory isn't clean, has skipped tracking files, or previously unignored files, you can force move the branch pointer.

git checkout b1
git branch -f master
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167