Overview
sync tells the system to write any data held in memory buffers out to the disk. Operating systems delay writes to be fast, so data you saved a moment ago may not be on the disk yet. sync before unplugging a drive, or before a risky step, makes sure it is.
Background
Today the name covers GNU sync, the sync that macOS ships, and the sync applet in BusyBox. The macOS manual has no separate page for sync, so no date is given. They agree on flushing all pending writes when run with no arguments.
Examples
Flush all pending writes; there is no output when it works:
sync && echo done
Flush after writing a file, before copying it away:
printf data > f.txt && sync && cat f.txt
Use it before a command that might crash the machine:
sync; echo flushed
Common mistakes
sync makes the data safe on the disk, but does not unmount a drive; use the system's eject or unmount command before removing it. It does not report errors in a useful way. On a busy system it can take a while. The file-system sync that real programs use is fsync on a file, not a command.
Portability
Plain sync is the same on all three. GNU adds -d, -f and file names to sync only part of the data, which macOS and BusyBox do not have in the same form. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check).
About macOS sync
This is the sync in the system folders of macOS. It follows the BSD implementation.
Apple notes
macOS sync takes no options and flushes all pending writes.
References
Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.