The term fuga was used as far back as the Middle Ages, but was initially used to refer to any kind of counterpoint, including canons, which are now thought of as distinct from fugues. The whole genre gets more distinct during the 16th century. But was also used before that time period too. Fugue as a theoretical term dates back to the 1300 By Jacobus of Liege when he wrote about Fuga. The fugue arose from the technique of “imitation”, where the same musical material was repeated starting on a different note. Gioseffo Zarlino was said to be one of the first to write fugue pieces. By the 1550s fugue was considered a technique of composition. It was in the Baroque period that the writing of fugues became central to composition, in part as a demonstration of compositional skill. But fugues were incorporated into loads of different musical forms of the time. Some baroque examples of people who wrote fugues are Jan Pieterszoon Sweelinck, Girolamo Frescobaldi, Johann Jakob Froberger. Some fugues during the Baroque period were pieces designed to teach contrapuntal technique to students During the Classical era, the fugue was no longer a central or even fully natural mode of musical composition. But both Haydn and Mozart had periods of their careers in which they in some sense “rediscovered” fugal writing and used it frequently in their work. But many other composers used fugue in their work too.
Fugue in the 20th century was used by composers like Stravinsky. But also some songs in jazz used fugue in such as Bach goes to town played by Benny Goodman and Concorde recorded by The modern jazz quartet.
here is an example of a fugue piece.
Fugue is a contrapuntal compositional technique in two or more voices, built on a a musical theme that is introduced at the beginning in imitation (repetition at different pitches) and which recurs frequently in the course of the composition. A fugue usually has three sections to it such as an exposition, a development, and a final entry that contains the return of the subject in the fugue’s tonic key. A fugue begins with the exposition of its subject in one of the voices alone in the tonic key. After this A second voice in the piece imitates this but transposed to a different key. This is called a ‘real answer’ or a ‘tonal answer’ depending on whether the voice is transposed into the same intervals as the previous voice. Development includes the development of the piece. This can be developed from the exposition using counterparts or free counterpoint. The closing section of a fugue often includes one or two counter-expositions. Which would be in the same key as the original exposition. Fugue is the most complex of contrapuntal forms.
Reference: Wikipedia- Fugue