Percent 20's answer is more comprehensive and portable in principle, but comes with two caveats:
For instance, you cannot store a custom icon in a Git repository. relies on extended attributes of the HFS+ filesystem, which are lost when copying the bundle to a filesystem that doesn't support them.The accepted answer works in principle, but: To complement the existing, helpful answers: