In medieval times, York was the main city of the North of England and the see of the Archbishop of York from AD 735. Yorkshire was England's largest shire in area.
York under its Viking name "Jorvik" was a petty kingdom in the Early Medieval period. In the interval between the fall of independent Jorvik under Eirik Bloodaxe, last King of Jorvik (d. 954), and the first creation of the Dukedom of York, there were a few Earls of York.
The title Duke of York was first created in the Peerage of England in 1385 for Edmund of Langley, the fourth surviving son of Edward III, and an important character in Shakespeare's Richard II. His son Edward, who inherited the title, was killed at the Battle of Agincourt in 1415. The title passed to Edward's nephew Richard, the son of Richard of Conisburgh, 3rd Earl of Cambridge (who had been executed for plotting against King Henry V). The younger Richard managed to obtain a restoration of the title, but when his eldest son, who inherited the title, became king in 1461 as Edward IV, the title merged into the Crown.
The title was next created for Richard of Shrewsbury, second son of King Edward IV. Richard was one of the Princes in the Tower, and, as he died without heirs, the title became extinct at his death.
The third creation was for Henry Tudor, second son of King Henry VII. When his elder brother Arthur, Prince of Wales, died in 1502, Henry became heir-apparent to the throne. When Henry ultimately became King Henry VIII in 1509, his titles merged into the crown.
The title was created for the fourth time for Charles Stuart, second son of James I. When his elder brother, Henry Frederick, Prince of Wales, died in 1612, Charles became heir-apparent. He was created Prince of Wales in 1616 and eventually became Charles I in 1625 when the title again merged into the Crown.
The fifth creation was in favour of James Stuart, the second son of Charles I. The city and state of New York in what is now the United States of America were named for this particular Duke of York. When his elder brother, King Charles II, died without heirs, James succeeded to the throne as King James II, and the title once again merged into the Crown.
In the early 18th century, the Jacobite claimant to the throne, James Francis Edward Stuart, son of James II, granted the title "Duke of York" (in the Jacobite Peerage) to his own second son, Henry. James Francis Edward Stuart was known to those who rejected his claims as "The Old Pretender"; his elder son Charles was called "The Young Pretender" (or "Bonnie Prince Charlie" among his supporters), and the younger son, Henry, who became a Roman Catholic cardinal, was known as the Cardinal Duke of York. To the Jacobites, they are Kings James III, Charles III, and Henry IX, respectively. (From the Jacobite perspective, this creation of the title merged into the Crown with Charles' death without legitimate issue, and Henry's succession to his rights.)
During the 18th century the double dukedom of York and Albany was created a number of times in the Peerage of Great Britain. The title was first held by Duke Ernest Augustus of Brunswick-Lüneburg, Bishop of Osnabrück, the youngest brother of King George I. He died without heirs. The second creation of the double dukedom was for Prince Edward, younger brother of King George III, who also died without heirs, having never married. The third and last creation of the double dukedom was for Prince Frederick Augustus, the second son of King George III. He served as Commander-in-Chief of the British Army for many years, and was the original "Grand old Duke of York" in the popular rhyme. He too died without heirs.
The sixth creation of the Dukedom of York (without being combined with Albany) was for Prince George of Wales, second son of the future King Edward VII. He was created Duke of York following the death of his elder brother, Prince Albert Victor, Duke of Clarence and Avondale. The title merged with the crown when George succeeded his father as King George V.
The seventh creation was for Prince Albert, second son of King George V, and younger brother of the future King Edward VIII. Albert came unexpectedly to the throne when his brother abdicated, and took the name George VI, the Dukedom then merging into the crown.
The title was created for the eighth time for Prince Andrew, second son of Queen Elizabeth II. At present (2018), he only has two daughters. Thus, if he has no future (legitimate) sons, the title will again become extinct at his death.
Aside from the first creation, every time the Dukedom of York has been created it has had only one occupant, that person either inheriting the throne or dying without male heirs.