Real-time collaborative programming enables a group of programmers to edit shared source code at the same time, which significantly complements the traditional non-real-time collaborative programming supported by version control systems. However, one critical issue with this emerging technique is the lack of integration with non-real-time collaboration. Specifically, contributions from multiple programmers in a real-time collaboration session cannot be distinguished and accurately recorded in the version control system. In this study, we propose a scheme that integrates real-time and non-real-time collaborative programming with a novel workflow, and contribute enabling techniques to realize such integration. As a proof-of-concept, we have successfully implemented two prototype systems named CoEclipse and CoIDEA, which allow programmers to closely collaborate in a real-time fashion while preserving the work's compatibility with traditional non-real-time collaboration. User evaluation and performance experiments have confirmed the feasibility of the approach and techniques, demonstrated the good system performance, and presented the satisfactory usability of the prototypes.