Tissue-resident memory T cells (TRM) persist in barrier tissues where they provide site-specific immune protection. However, the cell fate decisions and lineage pathways that lead to TRM commitment remains unclear. Here, using indexed single cell RNA-sequencing, we found that a distinct TRM precursor (pTRM) can be found in the secondary lymphoid organs early following infection. To characterize this population further, we developed a novel barcoding system where cellular division could be used as an unbiased proxy for cell fate, which allowed the permanent identification of T cells after infection based on the number of cell divisions experienced during T cell priming. Using this system, we show that pTRM undergo relatively fewer rounds of cellular division in the skin-draining lymph node after HSV infection, and these cells preferentially give rise to TRM in the tissue. Transcriptional profiling showed that a substantial number of TRM core signature genes are upregulated on pTRM early after T cell priming in the lymphoid organs. In all, we propose a two-wave differentiation pathway for TRM development. The first wave poises a precursor population at the site of priming and the second wave occurs within the tissue niche and commits the cell to the TRM fate. These findings provide a platform for manipulation of pTRM cells to enhance tissue-specific protection against infectious diseases and cancers or reduce autoimmune-related disease burden.