62

I have a master branch and a working branch_1. I want to 'move' branch_1 exactly as it is to master. So I want something like this:

git checkout master git merge branch_1 # I don't know what is correct... 

Things which I did but I got loads of files messed up with annoying conflicts. So now master contains exactly the same files of branch_1 avoiding any conflicts, just overwriting files. Any help?

4
  • One option would be to git reset --hard branch_1, but that loose all history in master that is not shared with branch_1. Commented Jan 30, 2013 at 13:35
  • What do you mean by "move" branch_1 to master? Do you just want to do a simple merge? Getting conflicts is not unusual in a merge, so there's nothing special about it. As the question is currently written, it is not clear what the problem is. Commented May 27, 2014 at 17:03
  • See also: How to use git merge --squash? Commented Jan 22, 2016 at 20:19
  • Does this answer your question? Merge development branch with master Commented Apr 9, 2020 at 7:08

4 Answers 4

72

Conflicts are going to happen if both branches have changes to the files. This is a good thing. Keeping your branches up-to-date with each other will prevent some of them . However over all, conflicts are not bad. The rebase option can also prevent many of them from happening.

git merge branch_1 

If you are on master, merging will bring the changes as you expect.

http://www.kernel.org/pub/software/scm/git/docs/git-merge.html

You could also

git rebase branch_1 

This will take the changes from branch_1 and append them to master without a merge commit.

http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html

Sign up to request clarification or add additional context in comments.

Comments

5

Maybe you should not merge?

  1. Checkout branch_1
  2. Rebase master changes into branch_1
  3. Fix any errors that might have occured after testing your code
  4. Checkout master
  5. Rebase branch_1 changes into master

or in code:

git checkout branch_1 git rebase master (...) git checkout master git rebase branch_1 

This also gives you the opportunity to squash several commits into one, if you want to make your changesets more dense, and prevents these annoying merge-commits in your history.

Comments

1

I took this code from thenetninja youtube channel and it works for me.

on non master branch

 git add . git commit -m "msg" git checkout master 

on master branch

 git merge <non master branch name> # fix any conflicts and try to run the software to test any error git add . # commit w/o any msg, as follows git commit git push origin master 

Comments

0

You can use git rebase branch_1 This will resolve the conflicts in the other branch while being on master branch.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.