He was educated at various private schools and at Bucknell University. In 1851, he was appointed to West Point, and graduated in 1855. Upon graduation, he was commissioned into the 2nd Dragoons, serving in various posts in the West. In September 1855, he was promoted and transferred to the 1st Dragoons, and served out the balance of his antebellum career in California, working as regimental adjutant. When the war broke out, he was a captain in the 3rd U.S. Cavalry, and was assigned to the newly formed 6th U.S. Cavalry. When volunteer units were organized, he was elected colonel of the 8th Pennsylvania Cavalry.
In that capacity, he served well on the Peninsula and in the Antietam Campaign. Accordingly, he was promoted to brigadier general of volunteers on November 20, 1862. By the spring of 1863, he commanded the Second Division of the Army of the Potomacs Cavalry Corps, a position he held until his resignation from the army in February 1865. He was a wing commander at Brandy Station, and served with great honor at East Cavalry Field during the third day of the Battle of Gettysburg. Most historians credit Greggs forethought with the victory on the East Cavalry Field. Known for being calm and brave under fire, Gregg tended to be deliberate and thorough. He rarely made a mistake in battle, although his late arrival at Brandy Station could have made the difference in determining the outcome of the battle.
During the 1864 Overland Campaign, Gregg again distinguished himself with conspicuous service. As a reward for his fine service, he received a promotion to brevet major general of volunteers on August 1, 1864, cited for highly meritorious and distinguished conduct throughout the Overland Campaign. Gregg continued to command the Second Division until he resigned his commissions on February 3, 1865 under mysterious circumstances; at least one historian has claimed that he was suffering from nervous anxiety that prohibited him from further commanding troops in the field. Gen. Philip H. Sheridan commented, it is to be regretted that he felt obliged a few months later to quit the service.
After a brief career in farming, President U.S. Grant appointed Gregg U.S. consul to Prague, and he served in this capacity for several years. Married to a member of the leading family of Reading, Pennsylvania, Gregg settled there after the war. He was extremely active in veterans activities, and was a leading, honored citizen of the community, which paid tribute to him with a handsome equestrian monument near his house. In 1907, he published a work titled, The Second Cavalry Division of the Army of the Potomac in the Gettysburg Campaign, which later appeared in Annals of the War. Gregg died on August 7, 1916, and was buried in Charles Evans Cemetery in Reading.