'Git merge branch into master

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?



Solution 1:[1]

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.

Solution 2:[2]

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 -u origin master

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sjas
Solution 2 shahul01