So, you have three branches:
There were commits done inside branch1 and branch2. Let's assume that you work on branch2 and branch1 is already merged into master. You could do the following
git checkout master
git merge branch2
However, you may have conflicts if both branches worked on the same files. If you have such a conflict, then you can run
git status
in order to see what the conflicting files are. Opening each and every file you will see sections like
<<<<<<<
=======
>>>>>>>
The first line above signifies the first branch and the last line signifies the end of the last branch. Between the lines you will find the different versions. You will need to figure out which are the correct lines from each and perform modifications until the code works. Finally, remove the lines above along with the content in-between.
However, you may want to avoid solving the conflicts inside master, because that's central and it is better to localize problems in my opinion, so what I actually do, assuming that I'm on branch2:
git status
git add myfile1
git add myfile2
git commit
git pull
git push
git checkout master
git pull
git checkout branch2
git merge master
If there are conflicts, then solve them and then
git checkout master
git merge branch2
EDIT:
Apparently there was an earlier version of master which differs from branch2, yet, branch1 would add commits that are not desired at this point. So solve it, first:
git checkout master
to view what's in master. Then see what the commits into master were via
git log
You will see a list of commits. Find the newest commit that's still good and you will see its hash, which is a long alphanumeric string. Let's call id for now, but you will need its actual value. Now switch back to your branch:
git checkout branch2
and merge that commit into your branch
git merge <hash>