The best way of measuring the mass is in principle using gravitational lensing, as mentioned in the first posted answer to this question. However, applying this method has become feasible only relatively recently, partly because lensing is relatively rare and requires 'lucky' alignment of the source and the lens, and thus a large telescope survey to find enough of them and with an excellent spatial resolution (typically below an arcsecond) to resolve the source images. Moreover, in detail it is hard to apply. You don't know the 'density profile' (radial distribution of mass in the galaxy) a priori, so you need to measure it. Therefore, ideally you need to have multiple sources of light behind a single galaxy at different angular locations, so that each source probes the galaxy mass M(R) enclosed at some radius. This can be done using the method called weak gravitational lensing (and it would take us beyond the scope of the question to talk about it). Anyway, this kind of measurement has started to happen only in recent years.
Traditionally in astrophysics, the mass of the galaxy is instead measured using various dynamical methods where velocities of stars are converted to the mass. But I disagree with Ernie that this is easy to do using Newton's Laws. The difficulties include the fact that you are only measuring the radial (and not tangential) velocity of the star(s) using spectroscopy; that the distribution of the mass of the galaxy may not be spherically symmetric, etc.
Traditionally people have used the virial theorem, most famously first used by Fritz Zwicky in 1933 to measure the mass of the Coma cluster of galaxies. In this approach, under some assumptions, one can relate the mass of the cluster to velocity dispersion of galaxies along the line of sight, and you can measure the latter as described in the earlier post to this question. (This brilliant logic, using existing measurements at the time, led Zwicky to announce that Coma must be dominated by invisible, dark, matter).
There are also other methods to get masses, but they are messy. Typically, one infers the mass-to-light ratio of the object (M/L), and then measures L to get M. These approaches have significant uncertainties. Therefore, as mentioned in the post above, gravitational lensing is in principle the cleanest method.