In any nation that is signatory to the Berne Convention, copyright (i.e., a monopoly on redistribution, derivatives, public display, etc.) is automatically in force for the author of a creative work. An author may use license to grant some rights to other people, and, even when using a free/open license, may place requirements on reuse, such as requiring attribution or copyleft terms. Anyone who exercises a copyright-restricted right without meeting the requirements of the author's license is liable to pay damages if sued in a court of law.
It's possible to register your copyright, though not necessary (in the U.S.) until you actually initiate a lawsuit. In the U.S., if you register your copyrighted work before infringement takes place, you can claim extra money in court, called "statutory damages", on top of whatever "actual damages" the infringement caused you. I expect that corporate-run open source projects may register their work in the Copyright Office, but I don't know.
For practical enforcement, the only real tools available to combat infringement are
- Hire a lawyer and take your infringer to court
- Threaten to do item #1 (this is less costly but may be sometimes less effective)
If you license your work under a free/open license and cannot afford a lawyer, the Open Source Initiative or Free Software Foundation may be responsive to a request for legal assistance in some form or another.
It seems like you may also be worried about a few other possibilities:
Someone violates your license and tries to pretend like they're the original author of your code. This is quite a bold move, and unlikely to succeed in a world where history of commits is either a matter of public record or at least privately logged by code-hosting providers. This seems to be more likely (though still extremely unlikely) for a project that doesn't conduct all development publicly.
Someone takes your code to make a clone of your project. This is explicitly allowed by all free and open source licenses, and is called a "fork". The fork still has to follow your license requirements (like attribution or copyleft) but otherwise may be as similar or different from your original project as the maintainer of the fork likes. Trademark law may prevent a fork from reusing your project name or logo.
A developer contributes code to your project, but it turns out they lacked legal permission to make that contribution, e.g., because it belonged to an employer or similar. This is a difficult case to handle, but generally projects deal with it by making contributors legally accept responsibility if any of their code turns out to be itself infringing. This is often done via a Contributor License Agreement (CLA) or a Developer Certificate of Origin (DCO).