Make it a condition of the code being included in the project, ideally as part of the software license.
There are a number of software licenses that do this; for example, in the Mozilla Public License:
Each Contributor hereby grants You a world-wide, royalty-free,
a.under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
b.under Patent Claims of such Contributor to make, use, sell, offer
for sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
The GPL, in particular, requires that all contributions made to a GPL project be licensed under the terms of the GPL. So you shouldn't have to do anything else, other than make it clear to the contributors that this is the arrangement.
If you believe that some contributors may insist on retaining some or all rights to their code, simply have them sign a statement that indicates they are assigning copyright to your company; specifically, that it is a work for hire. Make it a condition of them getting paid for the code. Note that, in most jurisdictions (at least in the United States), if they are employees, you should already own the code.
Disclaimer: I am not a lawyer. Treat this information accordingly.