In an unusual display of unity among divided Germans, West Berlin Mayor Dietrich Stobbe recently found himself surrounded in East Berlin by a cheering crowd.

The occasion marked the first public appearance by a West Berlin mayor in the East German capital for more than 20 years -- he was there to attend the installation of a new bishop. It provided East Germans with a rare chance to demonstrate what seems to remain a strong sense of attachment of the West.

In fact, while the world's superpowers are at odds following the Soviet invasion of Afghanistan, West and East Germany are carrying on a sort of love fest.

East Berlin's Communist leadership appears determined to keep its highly valued ties to the West, striking a fresh note of cordiality with Bonn and tempting West German firms with offers of lucrative contracts.

West Germany, in turn, has shown itself equally anxious to shelter its delicate links with the East from the current international political storm.

Normally a sensitive barometer of the East-West climate, inter-German relations remain relatively undisrupted by the war of nerves between Washington and Moscow.

"The Afghanistan crisis brought the two German states closer together," observed a Western diplomat recently. "They have never been so nice to each other. With their two big brothers quarreling, the two little ones stick together so nothing serious can happen."

Part of the reason for the increased closeness does seem to be a mutual interest in maintaining European detente in order to preserve valuable trade, credits and contacts built up during the last decade of relaxed relations.

But because the Kremlin appears to be allowing these relations to flourish, there may be an element of Soviet strategy at work. Some Western analysts suspect Moscow of encouraging East Germeny to cultivate West Germany in an attempt to soften Bonn's allegiance to the Western Alliance.

West German officials concede being somwhat confused about just what immediate intentions Moscow has toward them. Aides to Chancellor Helmut Schmidt are guessing that Kremlin leaders may themselves be divided on a coherent European strategy.

The Kremlin's signals to Bonn lately have been mixed, combining hard-line attacks West Germany for NATO's recent decision to station medium-range nuclear-tipped missiles in Europe, with soft-line gestures including an invitation from Soviet President Leonid Brezhnev for Schmidt to visit Moscow this summer.

Schmidt, although planning the trip, has been consulting with Western allies about its advisability, seeking especialy to win U. S. support so that he is not vulnerable at home to charges of appeasement or of weakening the Atlantic Alliance.

French President Valery Giscard D'Estaing's recent meeting with Brezhnev has lessened the burden on Schmidt's mission as an icebreaker but increased pressure on the German chancellor to come back with something more definite than the French pronouncement that no answers on Afghanistan were found.

Aides say the chief intent of Schmidt's visit will be to probe for Soviet flexibility on both a withdrawal from Afghanistan and, more important, on the start of European disarmament talks.

Much of the impetus for Schmidt's going is to preserve West Germany's strong links to Eastern Europe, over which Moscow exercises final judgment. A further aim may well be to portray Schmidt, who is running for reelection in October, as an agent of peace.

A sense of urgency is evident in the latest overture between the two Germanys. Both Bonn and East Berlin appear anxious to conclude as many deals as possible, fearing that the scope for independent action across the East-West divide could be sharply curtailed if the rift between the superpowers widens.

Both Germany are fully committed to their alliances and could not be expected to cling together if Moscow and Washington move farther apart.

Schmidt was able to meet East Germany leader Erich Honecker in Belgrade this month following the funeral of Yugoslav President Tito. "It was the first conference between the two German leaders in five years. A planned summit, initially scheduled for last February, had to be postponed because of East-West tension over Aftghanistan.

The postponement was a setback for both Germanys, but seemed to spur interest in cementing relations.

East Germany then announced at the March Leipzig Fair that it would seek longer terms marketing agreements with Western companies. Usually secretive foreign trade officials let it be known that they planned to buy industrial equipment worth up to $3.2 billion from the West during the next five years.

Inter-German trade is expected to top $5.6 billion this year. West Germany remains East Germany's most important Western trading partner, accounting for between 9 and 12 percent of East Germany's foreign trade. thanks in part to special privileges. There are no customs duties on goods moving between the two Germanys, and Bonn provides an interest-free line of credit to help finance the East's trade deficit.

As a further sign of eagerness to facilitate relations with its eastern neighbor, East Germany has quietly resumed the release of political prisoners to the West in return for West German payments. The flow was interrupted last year.

West Germany has accepted that better relations with the East will cost money. Earlier this month, the two German states signed an accord in which Bonn pledged to pay $270 million to improve road, rail and canal connections between the Germanys. Such accords have become the stuff of more relaxed relations since diplomatic freeze between Bonn and East Berlin cracked in 1972.

No official total is available for what Bonn has spent in the past decade for its policy of better relations with Eastern Europe -- for the release of the East's political prisoners, for improvements in transportation and communication links, and for the repatriation of ethnic Germans from Eastern Europe. One unofficial recent guess put the sum at $4.4 billion since 1970.

While reunification remains the constitutionally ordered, if increasingly unrealistic, goal of the Bonn government, the East German leadership has tried to build a sense of separate identity for its 17 million people. It promotes the idea of two German nations -- in contrast with the Bonn position of two German states within what is still one nation. The East attempts to eliminate remaining historical links to its Western neighbor with its population of 61 million.

East Berlin authorities generally try to squelch chances for open displays of East-West togetherness, such as the ovation given Mayor Stobbe in front of St. Hedwig's Cathedral by a crowd of 2,000 mostly young East Germans.

The last major public show of German unity in East Germany came during a visit to the southern town of Erfurt by West Germany's then chancellor, Willy Brandt, in 1971 -- a visit that signaled the unfolding of Bonn's eastern policy.

Because the contacts are perceived in the East as a threat to ideological purity and internal stability, East German Communists have appeared less enthusiastic about dente than Bonn. To the extent they have been interested at all, West Germans say, it is for the money. The East Germans resent this.

"Detente resulted from a diversity of interests, that is true. But our basic motivations have been congruent with the West -- namely, to establish a calm frontier and peaceful relations," said Max Schmidt, director of East Germany's Institute of International Politics and Economics, in a recent interview in East Berlin.

"The Economic interest is for us also a human problem," he added. "And I should note that lots of firms in West Germany live by our business."

Despite the recent warning, Schmidt said relations between the two Germanys may be approaching a plateau. The next leap, he said, will require acceptance by Bonn that East Germans belong to a separate nation.

"Continued normalization of relations heavily depends on mutual acceptance, on recognition of an equal footing," he said. "But I cannot see a solution in the foreseeable future.We are realistic enough to see that a change of constitution would be required [for West Germany] and cannot be done now."

In the meantime, Schmidt sees the next major move in East-West European relations coming in the disarmament field. "Political and economic dentente can be continued at this point but military detente has become paramount," he said.