City God belief in the North and South Dynasties, to the Ming and Qing Dynasties, gradually evolved from the guardian deity and the earthly government dispatched by the "yang official" counterpart of the "yin official", responsible for the size of the region's netherworld affairs. The city gods of each region were appointed by different people, or even chosen by the local people themselves, based on the criteria of loyalists who died as martyrs for their country, or upright and intelligent historical figures.
Ancient Chinese cities, generally using the earth to build walls, the walls are dug around the moat of the city, with water called pool, no water called god, so this trench to protect the city is called "god". City God refers to the moat, Ban Gu "two fugue preface": "the capital to repair the palace, dredge the city of God."
According to historical records, the city god belief in the north and south dynasty period has risen, Liang wuling king, a place in the townspeople in the preparation of the sacrifice of the city god, suddenly came out a red snake, around the cattle do not go. From this record, it can be seen that Liang sacrifices to the city god in southern China has been a very common thing. Until the Sui and Tang Dynasty unified the world, the first because the custom of sacrificing to the city god is only popular in the south of the Yangtze River, so in the beginning of the Tang Dynasty has not yet been included in the rituals, but after the Tang Dynasty, the states and counties have set up the City God Ancestral Shrine, which can be seen that at this time of the belief in the city god has been gradually developed into the national beliefs. At that time, Zhang Qujiang had "sacrificed Hongzhou City God Wen", the Five Dynasties on the occasion of the King of Wuyue have repaired the "City God Tablet", the Southern Song Dynasty Lu You also has "Ningde County City God Temple", which can be seen, since the Tang Dynasty, most of the counties have been sacrificed to the activities of the City God.