It has been said that the “enemy of my enemy is my friend”. It is this rationale that propels China and Germany to ally themselves in their common trade spat with the United States.

It’s also the reason behind the recent diplomatic flurry between the two countries. Premier Li Keqiang’s visit to Germany this week came just weeks after Chancellor Angela Merkel’s trip to China in May, and also just days ahead of a wider China-EU summit in Beijing.

US-China trade war: who wins, who loses?

Both Berlin and Beijing are seeking a closer alliance and a coordinated strategy in response to US President Donald Trump’s protectionist agenda. Merkel is also a Western politician Beijing has long courted. The world’s last major communist-ruled power is otherwise politically isolated from US-led free democracies.

Merkel’s 11 visits to China in her 12 years as chancellor have not only outnumbered any of her European trips, but have also exceeded those by three French presidents (Jacques Chirac, Nicolas Sarkozy and Francois Hollande) and three UK prime ministers (Tony Blair, Gordon Brown and David Cameron) combined.

Thus her visit to China and Li’s just-concluded reciprocal trip were widely watched. Berlin and Beijing share a vast bilateral and multilateral agenda on a range of vital global issues. They shared their opposition to Trump’s decision to pull out of the Iran nuclear deal. All signatories of that deal – China, Germany, the UK, France and Russia – opposed Trump’s abrupt and unilateral action. They also opposed Trump’s withdrawal from the Paris climate change agreement and his decision to move the US embassy in Israel from Tel Aviv to Jerusalem.

US-China trade war: bad for business is just the beginning

China and Germany, both export powerhouses, stand to lose from Trump’s trade war. As US and China slap tariffs on US$34 billion worth of each other’s imports, the US-European trade spat also lingers, with Germany as the chief target of Trump’s punitive tax on aluminium, steel and cars.

Beijing and Berlin have found a good reason to band together in the trade feud, as both run significant trade surpluses with the US. They have also agreed to cooperate on hi-tech goals and connect Germany’s “Industry 4.0” strategy with China’s “Made in China 2025” plan, which was singled out by Trump as major threat to US economic interests.

However, their solidarity over US trade moves has not wiped away all areas of discord. Much like the US, Germany has its own deep-rooted grievances against China. Even on trade issues, German companies have been complaining that they don’t get fair access to Chinese markets, and that German technology and expertise is too often copied or stolen in China.

There is widespread support in the US, EU, Japan and elsewhere for getting seriously tough on China for its long-standing unfair trade practises, such as infringements on intellectual property rights, forced technology transfers, China’s industrial policy and its treatment of state-owned enterprises.

Beijing is taking the EU to the World Trade Organisation court over the bloc’s failure to grant China market economy status. The EU is working with the US and Japan to press China to reduce its steel output. The EU is joining hands with the US, pressing China to open its banking and financial sectors, end state subsidies to industries, and grant foreign firms a level playing field.

Germany and China have also disagreed on a wide range of other issues, from politics to religion to regional and global security.

To see why Trump’s tariffs have hit a Chinese nerve, read history

For instance, Berlin has long pushed Beijing to release Liu Xia, the widow of the late Nobel Peace Prize winner Liu Xiaobo, who has been held under house arrest in Beijing since 2010, without any charge. While Beijing’s green light to allow Liu to go to Berlin on Tuesday is a Chinese gift to Germany, it underscored deep divisions and different beliefs between the two nations. As Merkel was talking to Li on Monday, her government’s human rights commissioner, Bärbel Kofler of the Social Democratic Party, accused China of “significantly worsening its human rights situation in last few years”.

Germany and China might be partners on some issues, but as political adversaries, Berlin and Beijing could never become allies, politically, ideologically and strategically speaking, against the US.

Cary Huang, a senior writer with the South China Morning Post, has been a China affairs columnist since the 1990s