In my experience with publishing in some journals, those journals require a signature on a copyright transfer agreement before an article can be published online or in print. Do I have to sign this agreement in order to publish or are there alternatives to this? What do I gain and/or lose by signing (or not signing) such an agreement?
It depends of what you mean by “an alternative”. If you mean an alternative to publish your article, you can certainly find other journals that don’t require that you grant them exclusive rights. Generally, that would mean an open-acess journal using the Creative Commons Attribution License (CC BY). Prime examples are the major OA publishers: PLOS, BioMed Central, and Hindawi.
If you mean publishing in a particular journal that requires coypright transfer, the answer is that granting them exclusive publishing rights is a publication condition, so that you can’t avoid it.
So what you gain in signing is... to have your article published by that journal. What you loose is highly variable among publishers. Often, they (who are now the copyright owners by virtue of the agreement) allow you (the authors) to keep some “rights” (I prefer to speak of “permissions”). Some publishers are quite generous, others not at all; you must carefully read the copyright agreement to know exactly what you will be able to do with your article.
Note also that some publishers ask (or propose as an option) an exclusive license instead of copyright transfer. Sometimes, they describe it as an advantage for authors, who keep the copyright on their work. But the truth is that some of these licenses give the publishers about the same rights as a complete copyright transfer, so that copyright ownership becomes an almost empty concept. See, for instance, Wiley, offering both without any difference in the actual rights transferred. Again, one has to carefully read the publication agreement.
Finally, in theory, one can always suggest changes in a copyright agreement, for instance deleting part of the text or adding some. There is also the SPARC Author Addendum, that you can attach to the copyright agreement, asking the publisher that you want to keep non-commercial use rights. The publisher may then accept these changes (usually by not responding, and publishing the article anyway), or refuse them. From what I read, there are both success and failure stories in that regard.
If you're feeling cheeky you can try editing the stock copyright transfer agreement they send out, to a wording that is more agreeable to you. I tried this for a book chapter once and I think I got away with it. Few returned CTA forms are actually read in detail by anyone.