The quick answer is learn the gender with the noun. There are no real hard and fast rules to know the gender of a noun in German. The best method is to learn the genders as you go. If you are making lists of vocabulary, make sure to write der/die/das in the margin, or m/f/nt, as a reminder. When you recite vocabulary aloud, always quote the gender alongside (i.e. say "das Meerschweinchen" [guinea pig] instead of simply "Meerschweinchen"). Another method some people find useful is visualisation and word association. To take a simple example, you need to remember that Tisch is masculine. Imagine a table wearing two pairs of trousers on its legs: der Tisch. I personally find that visualisation doesn't work as well with more abstract words, but if you can create a vivid enough image, it can still be beneficial! Take a look at the book "Fluent in Three Months" by Benny Lewis for a more detailed explanation.
Having said all that, there are some patterns. The most reliable is that nouns ending in -in are almost always, if not always, feminine. Some other patterns include:
*MASCULINE: ending in a consonant, -el, -er/-or, -ig, -ling, describes male person, days of the week
*FEMININE: -anz/enz, e, -ei, -heit/keit, -in, -schaft, -tät, -tion, -ung, -ur, describes female person
*NEUTER: -a, -um, -lein, -chen