McGilvery was born in Prospect, Maine. Born with a love for the sea, he was a sailor and then a ship master. He was in Brazil at Rio de Janeiro when the Civil War erupted. He soon returned home and raised the 6th Maine Battery, which first saw action at the battles of Cedar Mountain and Sulfur Springs in Western Virginia. At the Battle of Antietam, McGilvery's battery supported the attack of the XII Corps. On February 5, 1863, he was promoted to major and given command of the First Volunteer Brigade in the Artillery Reserve in the UnionArmy of the Potomac, which he commanded during the Chancellorsville Campaign. During the Gettysburg Campaign, on June 23, 1863, he was promoted to lieutenant colonel. On July 2, the second day of the battle of Gettysburg, McGilvery discovered a wide and undefended gap in the Union line along the southern end of Cemetery Ridge, north of Little Round Top. McGilvery patched together a line of artillery from various commands to fill the gap. Initially without infantry support, McGilvery's "Plum Run line" of fieldpieces was instrumental in halting the final Confederate advance toward the Union center. On July 3, the lengthy artillery line assisted in the repulse of Pickett's Charge, and in particular stopped the supporting attack of Confederate brigades under Cadmus Wilcox and David Lang. Promoted to colonel in September 1863, he continued to command his Artillery Reserve brigade until May 1864. He replaced Robert O. Tyler in command of the army’s reserve artillery and its ammunition train. He served with distinction in this role during the Overland Campaign and the Siege of Petersburg. On August 9, 1864, he was promoted to Chief of Artillery for the X Corps, commanding fifteen batteries. Only a week later, at the Battle of Deep Bottom, he was slightly wounded in a finger. The wound did not heal properly, and surgeons performed an amputation, during which McGilvery died from an overdose of chloroform being used as an anesthesia. His body was returned to his native Maine and buried in the Village Cemetery in Searsport.
Memorialization
Fort McGilvery, part of the Union earthworks at Petersburg constructed later during the siege, was named in his memory. The antebellum Post #30 of the Grand Army of the Republic in Maine was also named for McGilvery. In 2001, the Maine state legislature passed an act designating the first Saturday in September as Colonel Freeman McGilvery Day.