The first Guru Sri Nanak Dev, on his way to Kailash Parbat, passed through Pilibhit district of Uttar Pradesh. Here in the Tehri region, used to be a centre ofYogis called Gurakh-Matta. Guruji came to this place in 1515, and had prolonged discussion with them. He stayed with Yogis for a few days and gave them some more lessons on true religion. The place was later called Nanak Matta in the sacred memory of his visit to this place. In the time of the sixth Guru Sri HarGobind a Sikh called Almast used to serve this Shrine under the Pipal tree, sanctified by the Guru's visit. He was pestered by Gorakh Panthis to vacate the place as they wanted to re�establish their centre there. They went to the extent of burning the holy Pipal tree in a bid to oust Almast. Meanwhile Guru HarGobind who was on a tour to Garh Mukteshwar, Moradabad, Bareily and Pilibhit reached Nanakmatta. The Gorakh Pant his were so impressed by the presence of the Guru that they left the place for good. Thenceforth Gurdwara Nanakmatta has been sanctified by the holy feet of two Guru's, Sri Nanak Dev and Guru HarGobind.
About 140 km from this Shrine is another famous spot called Gurdwara Retha Sahib. When Guru Nanak along with companion Mardana visited this place, he took rest under a Soapnut (Retha) tree. Mardana felt hungry. Guruji asked him to pluck and eat the fruit from the soapnut tree. Soapnuts are bitter in taste but there on that particular branch they are sweet even today. Pilgrims bring a soapnut or two as parsad.
The historical Shrine of Nanak Mata (often pronounced Matta) associated with Guru Nanak Dev and Guru HarGobind is situated on the bank of Deoha stream, since dammed into a reservoir named Nanak Sagar, 15 kilometres west of Khatema Railway Station on the Pilibhit-Tanakpur metre-gauge section of North-Eastern Railway. This used to be retreat of Gorakhpanthi Nath Yogis and was called Gorakh Mata when Guru Nanak Dev came here during his travels in early sixteenth century. The Yogis at first behaved contemptuously towards the Guru and tried to overawe him with their occult powers. But as he remained undaunted and unaffected by their rudeness and miracle-making, they agreed to talk to him. Guru Nanak Dev impressed upon them the impropriety and unrighteousness of their path of renunciation, and exhorted them to live a pious yet active life of a God-oriented man of the world. The place thereafter became an UDasi Shrine named Nanak Mata. A century later, when Bhai Almast came to preach the message of the Gurus in the eastern provinces, he found Nanak Mata again occupied by Nath Yogis. Finding himself unable to evict them, he sent word for help to Guru HarGobind, who was then residing at Darauli Bhai. The Guru at once reached Nanak Mata, chastised the Yogis and revived the Sikh Shrine. Almast made Nanak Mata his principal preaching centre for the rest of his life, and it continued to be served by UDasi priests after his death. Nawab Asaf-ud-Daula of Lucknow once visited it and made a large endowment in land with an annual rental value of Rs.5000. An official document Wajab-ul-Arz Parganah Nanak Mata, dated 1314 Fasali (A.D. 1906-07) contains a provision under which every tenant while paying rent was also to pay one rupee for the mahant of the Shrine. The economic prosperity brought in mutual rivalry among the priests. There was litigation entered into by Mahant Amar Das and his disciple Harnam Das. Taking advantage of this, third person Chaudhari Ram Singh occupied the Shrine and its property. The management of the Shrine deteriorated. Some local Devotees brought the matter to the notice of the Shiromani Gurdwara Parbandhak Committee and the Chief Khalsa Diwan, besides addressing complaints to the Deputy Commissioner of the district and the provincial governor. A Panthic convention was held on 26th and 27th August 1933 and Gurdwara Nanak Mata Sudhar Committee was formed under the chairmanship of Sardar Santokh Singh, Chief Engineer Pilibhit with Inderjit Singh and Balwant Singh of Kathgodam, Ram Singh of Bareilly and Sardar Bahadur Bhagat Singh as member. The matter was taken to the court and it having been decided, on 20th August 1935, in favour of the committee, it took over possession from the Receive, appointed earlier by the Court, on 19th September 1935.