The Edinburgh and Bathgate Railway was opened from a junction near Ratho to Bathgate, in 1849. The owning company immediately leased the line to the Edinburgh and Glasgow Railway.
From the following year, shale oil was extracted in the area, and the line became very successful from that traffic. Other railways joined at Bathgate and the line later became part of a through route from Edinburgh to Glasgow via Airdrie.
In 1956 the passenger service was withdrawn, but it was reinstated from Edinburgh to Bathgate in 1986. In 2010 the through route to Airdrie and Glasgow was reopened and electrified, and the line continues in heavy passenger use at the present day.
The Edinburgh and Bathgate Railway (E&BR) was authorised by Act of Parliament on 3 August 1846. The main line of 11 miles (17 km) was to run to Bathgate, then an important manufacturing town, from a junction near Ratho on the Edinburgh and Glasgow Railway main line. In addition there were to be branches to Midcalder, to Binny Quarries, from Barrack to Whitburn, and a loop from Whitburn to Bathgate, though in fact only one of these was built by the E&BR. The authorised capital was £250,000. Two subsequent Acts, in 1847 and 1848, authorised deviations.
The engineer for the work was Thomas Grainger.
The only branch that was built by the E&BR was to Uphall, and from there a mineral railway extension ran to the Binny Quarry, near Ecclesmachen. The main line to Bathgate was opened on 12 November 1849. The company had been encouraged by the E&GR, and the E&BR leased its line to the E&GR for 999 years from the date of opening. The lease charge was 4% of the capital cost of the line plus a proportion of receipts.
As a shell company the E&BR Company remained in existence until the grouping of the railways in 1923 (see below).
The initial stations from Bathgate Junction (near Ratho) were Broxburn, Houston, and Bathgate.
Bathgate was an established centre of traditional industries when the line was proposed, but the situation was revolutionised when James Young, an industrial chemist, had developed an industrial process of manufacturing paraffin from torbanite, a type of oil shale. He had obtained a patent for the process in October 1850, and the torbanite had been discovered on the Torbanehill estate, about halfway between Bathgate and Whitburn. Young joined in partnership with Edward William Binney and Edward Meldrum and the Bathgate Works started operations in February 1851. This was the first commercial oil works in the world. When the torbanite was exhausted, shale rocks were exploited, at Bathgate and elsewhere in the locality, and although they had an inferior oil content they were nonetheless commercially desirable. The Edinburgh and Glasgow Railway built a branch line from the E&BR line to Blackhall, connecting Young's oil processing plant; the line opened in 1850 and diverged from the E&BR immediately east of the Bathgate station.