I have trouble memorizing so I decide to try and know how to sing the parts by heart but it is hard especially for baroque because you can sing one part but don't know how the other part sound like at the same time
This probably isn't the answer you want to hear, but I think the real answer here is one word: Experience.
Assuming you have an aptitude for music (which based on some of your other questions on this site it seems like you probably have), you will just start to develop an internal piano over time. Some day, you will be able to look at a piece of music and "play" the entire thing in your head just by reading the music.
One thing you can do, however, to help develop that internal piano sooner is to do a lot of sightreading. Sightread, sightread, sightread. Sightreading is, at its most basic form, the ability to look at a piece of music and interpret it on the spot. At first, being able to sightread is an exercise of "how quickly can I read notes and make my fingers do the right thing". As you become a more advanced sightreader, however, you will start to be able to feel the music. You will be able to hear it as you're playing it. By the time you've reached that point, you will probably be able to start putting together entire pieces in your head.
As with most everything in the world of music, it comes down to 3 things: Practice, Practice, and more Practice. :)
Other answers already provide good information, but regarding the issue of memorizing a piece I think it's worth to add a couple of points.
As Lawrence Payne said, practising is the fundamental approach for memorizing a piece. But this will give you mostly muscle memory, and muscle alone is not very reliable, specially if not refreshed frequently.
To complement muscle memory it is then necessary to engage "brain" memory in a more proactive way.
First of all try to get a theoretical/conceptual understanding of the piece, which can be done at the different levels depending on your current skills: formal structure, motifs and harmony.
Secondly, practice by sections DON'T start always at the beginning of the piece. Make a point of being able to start playing the piece at as many different points as practically possible. Say, at the beginning of each formal section, or even each musical phrase.
Associate formal information (e.g. chords, motif a, b or c, etc.) with each separate section. Make a point of mentally (or even verbally) invoking such information when starting to play a section.
Even without a deep knowledge of harmony or formal analisys, separating the piece by sections and having an explicit memory of each section, rather than a purely sequential memory of the whole, is of tremendous value in allowing your "conceptual" memory to cooperate with your muscle memory to give a much more reliable performance.
Kyle Martins advice about sight reading is also important, as some of the skills involved in sight reading are also involved in understanding and memorizing the piece (scales, chords, patterns of repetition, etc.). To be a good sight reader you have to develop techniques to somewhat anticipate, to a certain extent, what comes next. A line of melody in a certain scale, an arpegiatted chord, a common chord progression or cadence, etc. Now, these are exactly the tools that may help you memorize a piece by chunks rather than solely note by note.
So these skills are interdependent and it's best to work at all of them in a balanced way than to focus exclusively in one of them.
Caveat: I use some terms ("brain" memory and the like) in a coloquial (and surely not formally correct) way, as I'm not a psychologist. I hope I have been able to transmit the idea, though.