Look up journal's copyright restrictions
To find out a specific journal's expectations regarding transferring copyright, search for their copyright policies. This can usually be found in their "rights and permissions" or "author rights" section.
Use an author addendum to negotiate your rights as the author
An author addendum is a proposed modification to a publisher's standard copyright transfer agreement. If accepted, it allows the author to retain key rights. Publishing agreements are negotiable, so open a conversation with the publisher by including an author addendum in the publication agreement. For an overview of the issues involved around giving up your copyright, as well as a sample author addendum, please see "Using the SPARC Canadian Author Addendum to secure your rights as the author of a journal article".
For articles
For books