At the first checkpoint north of the monastery at Tanoboase, central Ghana, the soldier told me the herders were travelling south in search of rain. I must take care, he warned. The herders carried sticks of wood which were hard as iron. They would see me and see dollars.

I was en route from the Ghanaian coast to Tengzug, the great shrine of the Tongo Hills in the country’s far north, and the soldier’s warning was one of many stories I’d been told about the Sahelian herders. In the library of the monastery, in which I’d stayed for a week, I’d read in a book of folklore how at the start of time a snake had led the first herder to a river.

On the floodplain, cattle grazed. The snake told the herder to cut a stick from an ebony tree, and that any of the cattle he touched with the stick would always follow his people. So it was, the book said, that the herder and his animals were forever bound.

Sixty miles north of the monastery — two days’ walking in blistering heat — I sat to eat in a dust yard in the village of Dawadawa. Korfi, who had taken me in, given me food and a place to set my tent, told me that in times of drought the herders would slit the throat of a live cow and drink straight from its neck, before sewing up the wound and walking on. I wondered as he told it, the embers of the fire dying before us, if that story was for real or a kind of desert myth, a way to show, viscerally, how the cattle were the lifeblood of the people.

The road near the Ghana-Togo border, west of Cinkassé

Listening to such tales, I came to see in the lives of those nomads something of what I hoped for from the desert. The freedom to roam. Hardship. A rawer struggle. A year earlier, sitting before a screen in an office, as the idea for the journey began to crystallise in my mind, I pictured a desert. I imagined myself walking a dust road into a distance. I’d feel free, I’d thought. The inertia I felt, six floors up, looking out to the grey skies above Liverpool Street Station, in a building where the lights never turned off, the lethargy, the taste of the office canteen, the stale air — all would be burnt off by a long walk in the desert sun. Just a pack on my back, a trail at my feet; that distance would change me, I thought. I’d shed the roll of fat that hung from my belly. The soles of my feet would harden. I’d let the heat and the dust winds grind away the office worker I’d become. I’d emerge more like the nomad in the stories.

European travellers often come to the desert with such ideas. The desert nomad is drawn as the ultimate free spirit, while the journey in the nomad’s imagined footsteps is a way out. Back home, I’d scrawled notes in the margins of the desert books I cherished, accounts of Saharan journeys by Saint-Exupéry, Isabelle Eberhardt, Paul Bowles. Through them, over years, I built in my mind an idea of how a landscape — a desert way of life — might work to mould a person. Those books, and the mind-wandering they generated, evolved, as my life seemed to be veering off course, into plans for my own journey: a walk of 1,000 miles in the hope of resetting myself. The journey would take me on foot from Accra, on Ghana’s coast, to Ouidah, an ancient spiritual centre in Benin, passing in an arc via Tengzug, a hilltop shrine on the edge of the Sahel.

By the time I passed Dawadawa, I had been travelling for close to six weeks, and most of the illusions of the walk as some feat of endurance through which I’d become a stronger person had fallen away. Day by day, I’d come to see how helpless I was, how reliant on those who pointed the way to the next village, and on those who gave me food and a place to set my tent each night.

Any final illusion that I knew anything of a nomad’s journey, or that I might attain some understanding of that life from my walk, collapsed as I passed the first herder on the road, a day north of Dawadawa. It was still early, but already the heat was rising from the tarmac and, ahead, the horizon seemed to melt. Dust flowed from the ground, to which pale scrub clung. The animals the herder led were gaunt, with ribs that looked like famine, and great, long horns.

Closer, I saw the man was young, perhaps no older than 15. He carried a flask, a knife, a thin stick. He wore a football shirt and had a blue cross tattooed on his forehead. I raised my stick in greeting, and smiled, hoping for some acknowledgment, a sign that he saw, as I wanted him to, that we were both out there, on the edge of the world, together. He paid me no attention, and walked on with his animals into the scrub.

I thought often of the herder over the coming days, as I continued on the road for Tengzug, then 200 miles further north. Each day, barely perceptible at the slow pace of the walk, the land was drying, the distance between the settlements drawing out. At times the horizon appeared unbroken in every direction, just a low plain of orange gravel, the thorns and the shea, and I felt in those moments that I was drifting, like one lost at sea. During those hours, as I clung to the comfort of the road, I wondered how far the herder had come, how he navigated over ground and distance that seemed to me unfathomable.

On the nights when I was close to no village, I sat with my back to my tent, staring out towards the setting sun, and wondered how far the next person was from me, whether in the far distance I could make out dust rising, the movement of a herd where land and sky became one. I sat until the light died.

Some mornings I woke before dawn, in an effort to travel some miles before the heat. Walking through the darkness, I craved the light. Those final moments before the sun broke, the air cool, the sky grey-blue, the land liquid like sea, were my favourite of the day. Each hour from then, the heat rose. I played mind games to keep me moving. The next tree I passed, I told myself, I’d take off my pack and stretch. If a cloud came across the sun, I’d stop and spray water on my face. Hours went by. Sometimes a cattle truck passed. Dust drifted across the sky. Scraps of plastic flickered in the thorns. The sun slowly moved.

The day I reached Yapei, at the crossing of the White Volta, I’d walked 30 miles since dawn. My eyes stung. Ahead, I could see the river, which moved with the sluggishness of a body of oil. Corrugated roofs crowded the banks. I’d run out of water, and the last moisture in my mouth had burnt out. My legs shook. As I crossed the little bridge, men rushed towards me with phone cards, DVDs, fish on rope. I felt relief to have arrived, a feeling so strong it numbed me. My vision went, and I collapsed.

I was unsure how long I’d been out for when I woke on a mat beside the mosque, an old man pouring water on my face. I fell, the man said. But a truck will pass. Yes, the men around him nodded, surely a truck will pass. It was hours before the first vehicle came. The old man shouted “Tamale!”, the next town, to the driver. I would find a doctor there, he said. Dust drifted across the headlights, while the men hoisted me, and then my pack, to the roof. Looking back as their waving figures receded in the distance behind, I thought again of the herder and wondered, far from the roads, who would pick him up if he fell.

Stone formations in the Tongo Hills area of northern Ghana

By the time I took a track into the Tongo Hills, the uplands that rise from the dry grasses close to the Burkina Faso border, I’d been walking for two months. Clambering over the lip of the final hill, I saw Tengzug for the first time. The settlement, with baobabs growing beyond the outer walls, looked to have been carved from the ground. Sand walls, smoothed by dust winds, enclosed alleys and low houses, some painted with murals of whales, cattle, elephants. As I got closer, I saw animal skulls nailed to doorways. Shells and bones were set into the rims of the walls. A bare-chested man handed me a bowl of corn. Are you an Arab? he asked. Pilgrims come from all places, he said.

There was a time when Tengzug was revered as one of the most powerful sites of healing in this part of west Africa, and the shrine received pilgrims from across the region. Such was the reputation of Tonna’ab, the local spirit, that people travelled from across the country to carry earth back from Tengzug to establish satellite shrines. In 1911, soldiers from the Gold Coast Regiment marched with wheel-mounted machine guns to Tengzug — then among the last settlements of what is now Ghana to submit to British colonial rule — in an effort to compel the shutting of the shrine, and to cease the tide of pilgrims. The soldiers followed a long line of my people who had come to these lands to enslave, to murder. Ultimately, the soldiers failed; pilgrims still come.

In the hills above the village, the priest received me in a cave, in which he sat beside a mass of tangled rope. Why had I come? he asked. In shrines I had visited previously, I’d often felt self-conscious in these moments, as if my being there was turning something sacred into a Disneyland. I was drawn to the idea of walking to a shrine on a mountain in the desert, I said to the priest. Tonna’ab helps all humankind, he replied.

The priest’s question, asked as my mind was beginning to turn to the next phase of my journey, the 600 miles south through Togo and Benin to the sea, caused me to wonder what I’d taken from the miles I’d walked so far. I thought back to the office I’d left, the feeling of inertia that had seemed to swallow me there. And I thought of the herder, walking out to the vast distance with his cattle.

In the herder’s language, Fula, there is the concept of ndimaaku, being free. In the context of nomadic pastoralism, in part this means being able to roam and graze cattle where one pleases, a right now challenged by borders erected by those who colonised these places a century ago, and by the desertification of lands that once supported animals. My journey involved nothing like the exertion of the herder, and I still cannot say what freedom means to him, but I felt that I had at least come a little closer to what I had set out in search of: a feeling of freedom only attainable in motion. For me, I realised, there had been a liberation in the rhythm of the miles, the slow monotony of keeping as uninterrupted a cycle as possible. Sleeping, waking, walking.

And now, back in London, I think more and more of the freedom I felt in those months. As I take my daily lockdown stroll on Wormwood Scrubs, or west along the river — walking has, once again, become the only way out of inertia. Although I’m thousands of miles from the herder, again I’ve come to appreciate the mental relief of time on foot, and more than ever I yearn for what in his language is called ndimaaku.

Rob Martineau is the author of ‘Waypoints: A Journey on Foot’, published this month by Jonathan Cape

Follow on Twitter to find out about our latest stories first