Briefly after the revolution, Libya experienced a period of calm before it was plunged yet again into another conflict.

This week, fighting erupted between rival militias in Tripoli, shattering a period of calm that lasted since March. The UN-backed government lost more than 50 fighters.

Also, Egyptian air force planes continue to strike camps near Derna, in east Libya. The air strikes were a response to a deadly attack against Christians in Egypt that took place last Friday. The Egyptian president claims that the area hosts “terrorist camps”.

There are three rival governments vying for control of Libya. There are two governments in Tripoli. One of them is the UN-backed Government of National Accord (GNA), which has struggled to exert authority following the 2015 peace deal. This is mainly due to the refusal of authorities controlling eastern Libya to recognise the GNA as Libya’s official government.

Here is a breakdown of how Libya got to this point moving from a promising transitional government to a state of ongoing conflict.

The Uprising

Buoyed by the other revolts in neighbouring Arab countries such as Tunisia and Egypt, Libya’s popular uprising against the authoritarian rule of Muammar Gaddafi began in February 2011.

What started off as protests against Gaddafi’s rule quickly descended into an armed conflict as security forces, loyal to Gaddafi, clashed with protesters, using warplanes to bomb them.

As protests entered their second week, almost 300 civilians were reported to have been killed.

The increasing number of civilian casualties led the United Nations to pass a resolution that designated Libya a no-fly zone. The resolution also called for the protection of civilians by any means necessary.

On March 31, NATO began carrying out air strikes as a result of the UN’s proposal to protect civilians.

After the conclusion of the operation, a UN report found that 60 civilians were killed by NATO air strikes and 55 wounded. The report also states that NATO did not carry thorough investigations regarding air raids that killed civilians.

Libya, a country of about 6.4 million people, is mainly made up of Arab and Berber ethnicities. There are also nomadic tribes to the south, such as the Tuareg and Tebu tribes.

The country was ruled by Gaddafi for 42 years, making him the longest-reigning leader in the Arab world. He came to power in 1969 after a bloodless coup against Libya’s King Idris I.

Libya’s economy was heavily dependent on its crude oil industry. Before the popular uprising, the country produced around 1.6 million barrels a day. After the popular uprising, oil production plummeted to zero, but rose up again after the first elections.

However, when the conflict flared up again in 2014, oil production fell, especially after rival militias started fighting over key oil facilities. As of early 2017, Libya produces around 700,000 barrels a day, according to the National Oil Corp.

The country’s GDP was heavily reliant on Libya’s oil industry, so it drastically fell after the uprising.

Eight months after the uprising, the internationally recognised National Transition Council of Libya, largely comprising loosely organised local armed groups that sprang up in towns such as Beneghazi and Misrata as a governing authority for the uprising, announced the “liberation” of Libya.

However, Libyans were soon frustrated with the interim government’s failure to act.

The NTC had promised to fulfill a long list of needs, including a functioning justice system, a reconciliation process for officials who served the old administration, the disarming of militia, building functional national security forces, rebuilding destroyed areas and delivering basic services such as healthcare.

A great component of their failure was the stagnation of Libya’s economy following the removal of Gaddafi. International advisers and foreign investors were reluctant to return to an environment where the government would not sign long-term agreements and could not guarantee security.

By July 2012, 2.7 million people registered to vote in Libya’s first free election. The General National Congress (GNC) replaced the NTC after the elections.

Benghazi US Consulate Attack

In September 2012, a heavily armed group stormed the US Special Mission in Benghazi, and killed US Ambassador J Christopher Stevens and three other Americans.

Following the attack, the US and Britain withdrew some diplomatic staff from Libya, amid security concerns over a flare-up in political unrest.

TIMELINE: Three years after Libya’s uprising

Elections of 2014

Frustration against the GNC was exacerbated by its refusal to step down after the mandate for their rule expired. Thousands of Libyans protested in Tripoli and Benghazi, demanding the interim government step down as promised.

GNC members had extended the mandate to provide a special assembly with time to write a new constitution, which they claimed was imperative to a stable Libya.

Libya’s second elections since the popular uprising were marred by violence. The voter turnout was low. Instead of voting for parties, Libyans voted for members of parliament in an attempt to ease tensions.

The GNC handed power over to the newly elected House of Representatives (HoR), while a battle raged in Tripoi’s airport. “Libya could have stabilised after the popular uprising if the government didn’t split into rivalling factions,” said Nizar Krikshi, a Libyan political analyst.

“With [General Khalifa] Haftar’s operation dignity, it became obvious that armed forces would be used to resolve the rivalry between the different political parties,” Krikshi told Al Jazeera.

Who is Khalifa Haftar?

In May 2014, General Khalifa Haftar, a military defector from Gaddafi’s era, launched his campaign, Operation Dignity, claiming to protect Libya from “terrorists”. Forces loyal to Haftar fought against armed groups in Benghazi, and took over the strategic Libyan city.

Haftar defected to the US in the late 1980s. He returned to Libya after the downfall of Gaddafi and is currently fighting other forces for the control of Libya.

In the lead up to his operation, Haftar garnered support from local tribes and businessmen. He gathered former soldiers of the Libyan army to beef up his armed forces, and appealed to foreign support presenting himself as a key to Libya’s stability, according to the International Center for Counter-Terrorism (ICCT).

Some viewed his operation as an attempted coup similar to the one Abdel Fattah el-Sisi carried out in Egypt in July 2013.

The violence spread to Tripoli, where the newly formed Libya Dawn coalition, led by armed groups from Misrata and their allies, fought against Haftar’s Libyan National Army (LNA) at the capital’s international airport.

Armed groups from Zintan, who had controlled the airport since 2011, also took part in the clashes over the airport. Libya Dawn then gained control of the airport and Tripoli.

This victory set the tone for two opposing governments in Libya.

The GNC was reinstated in Tripoli while the elected HoR moved to the eastern city of Tobruk.

However, in November 2014, the Libyan Supreme Court ruled that the HoR was unconstitutional after the court found that the committee behind the election law violated Libya’s provisional constitution.

Unifying Libya’s two governments

A UN peace deal, the Skhirat agreement, was signed in December 2015 and attempted to broker peace in the country by proposing a unified government.

The deal put together a six-point plan to end the conflict. It proposed a one-year transitional period during which they could decide on issues such as disarmament, control of the country’s airports and the writing of a constitution.

At the time it was signed, a presidential council was expected to lead during the transitional period. The planned government was made up of a nine-member presidential council called the General National Accord (GNA), the elected HoR, and a State Council to serve as consultative chamber.

It fell on the presidential council to name a new government within a month, which a UN Security Council resolution promised to endorse.

A unified government was also seen as a way to end the rising threat of Islamic State group ISIL, also known as ISIS, in Libya. Western officials stated that the priority following the political agreement was to rebuild a national army to fight ISIL.

Haftar returned to Libya from the US after the downfall of Gaddafi and is currently fighting other forces for the control of Libya [Reuters]

Who controls Libya’s oil crescent?

A few months after Libya’s tentative steps towards peace, Haftar and his armed forces launched a second offensive and took over key oil ports in mid-September 2016.

His forces fought off guards to gain control of the oil terminals at Ras Lanuf, Al-Sidra and Zuwaytania, and they finally secured Brega unopposed.

It was the first time Haftar’s forces, as well as fighters loyal to the GNA, clashed directly since the unity government started working in Tripoli in March. Haftar’s control of the oil ports is widely seen as a trump card for political negotiations.

Previously, the oil ports were controlled by the Petroleum Facilities Guard, an armed group led by Ibrahim Jathran and loyal to the Tripoli-based government.

Earlier this year, the Benghazi Brigade, an armed group formed of fighters exiled from Benghazi after Haftar seized control of it, took over two of the oil ports on their fight back to Benghazi.

The armed group managed to hold on to the ports for only a short period before Haftar’s Libyan National Army (LNA) recaptured them.

INTERACTIVE: The Battle for Libya’s Oil

The armed group managed to hold on to the ports only for a short period before Haftar’s Libyan National Army (LNA) recaptured them.

The back and forth is an extension of the two-year military campaign Haftar has been fighting with his LNA forces against armed groups in Benghazi and elsewhere in the east.

The latest fighting around the terminals raised the prospect of a new escalation of violence and put at risk a sharp boost to Libya’s oil production achieved after the LNA took over four ports in September, ending a blockade at three of them.

Though Es Sider and Ras Lanuf have been reopened for exports, they were badly damaged in past fighting and are operating well below capacity. Oil is Libya’s key asset, and revenue from crude exports is vital if the GNA is to rebuild the economy and infrastructure of the North African nation.

Currently, there are two National Oil Councils (NOC), one created by the government in eastern Libya and based in Benghazi, and the other one in Tripoli. The NOC in Benghazi has attempted to gain control over oil operations but remains unsuccessful.

Haftar’s Allies

Haftar has sought out regional and international allies since he entered Libya’s main political stage. Recently, he was seen with Russian officials, which spurred speculation about the possibility of Russia’s presence in Libya.

When Haftar briefly lost two strategic oil ports to rival armed forces, news reports suggested that Russia deployed private military contractors to facilities near Benghazi. However, this was denied by all parties involved.

While Russia increases its support for Haftar, other foreign sponsors have already provided outright military help or political assistance for the general. Relying on Egypt, the UAE and France, Haftar succeeded in creating a stalemate that has gradually eroded the UN-backed government’s chances of controlling the country.

What are Libya’s key armed Groups?

The Libyan National Army: Haftar’s armed forces, the Libyan National Army, also position themselves as the official armed forces of the elected House of Representatives (HoR) in Tobruk. It is reportedly made up of mercenaries and militias, along with military men from Gaddafi’s era.

“The parliament in Tobruk gave Haftar’s army legitimacy, which is a crisis because during Gaddafi’s era, there wasn’t a functioning institutional army, so the idea that Libya has a national army is not valid,” Krikshi explained.

The Benghazi Brigade: Fighters exiled from Benghazi after it fell to Haftar in 2014 formed the Benghazi Brigade in 2016. Their declared goal is returning to Benghazi, so they continuously clash with Haftar’s forces. They recently captured two oil ports on their way to Benghazi, but quickly lost them to the LNA.

Previously, the oil ports were under the command of the Petroleum Facilities Guard. They took over the country’s main oil facilities in 2013 and attempted to sell oil, which according to the European Council on Foreign Relations “cost Libya billions in lost revenue”. They lost the oil ports to the LNA in 2016.

The Libya Dawn Alliance: This alliance fought Haftar’s forces and Zintan fighters in Tripoli during Operation Dignity in 2014. The group, which was made of different fighters including ones from Misrata, fractured soon after owing to internal tensions.

Al Bunyan Al Marsous: Misrata fighters make up the largest part of Bunyan Al Marsous, the coalition of armed forces that fought ISIL. Hundreds of them died before they declared victory in Sirte late 2016.

“The proliferation of weapons in Libya and the different militias negate the existence of politically legitimate institutions that could run the country,” Krikshi said, in reference to the abundance of different warring factions in the country.

“The militias in Libya, even though they each belong to a different arm of government, only fight for their own agenda at the end of the day.”

What happened in Derna?

On Saturday, Egyptian air force planes carried out six air strikes at camps near Derna, in the east, in response to a deadly attack against Christians in Egypt. The Egyptian president claimed that the area hosted “terrorist camps”. However, Al Jazeera’s Mahmoud Abdelwahed reported that “sources on the ground say that only civilian properties like houses, farms and vehicles have been damaged”.

In the past two years, the Egyptian air force has carried out several strikes on Derna, notably in February 2015 and March 2016, which killed women and children.

While rival factions battled over the government, ISIL seized the opportunity to expand in Libya.

Derna was home to Libyan fighters returning from Syria who later formed ISIL in 2014.

“The catalyst for the formation of ISIL was the return of fighters from Syria to Derna in 2014,” according to a research paper issued by the Carnegie Middle East Center in March 2015.

Other armed groups coalesced around the returned fighters, who called themselves the Islamic Youth Shura Council.

They also launched high-profile attacks, such as the suicide bombing at the Corinthia Hotel in Tripoli in January 2015 and public mass executions, such as the propaganda video purportedly showing the beheadings of 21 Egyptian Christians on what was believed to be a beach in Sirte.

The ISIL-affiliated faction then started to expand west. They arrived in the coastal town of Sirte on February 2015, where they paraded around in vehicles declaring allegiance to ISIL.

The coastal city of Sirte, about 450km east of Tripoli, is the hometown of former leader Muammar Gaddafi’s tribe. Since the 2011 uprising, residents of Sirte have felt angry and marginalised – especially Gaddafi’s tribe members whose relatives were killed and whose homes were ransacked.

READ MORE: How serious is the ISIL threat in Libya?

Sirte becomes the first stronghold that ISIL totally controls outside Iraq and Syria, and was reportedly home to the group’s strongest presence within Libya.

Sirte is also geographically significant, with a seaport offering access to southern Europe across the Mediterranean Sea.

In May 2016, Pro-GNA forces began a campaign against ISIL in Sirte. A few months later, the US launched air strikes at the behest of the GNA. After seven months of fighting and hundreds of casualties, Sirte was retaken by GNA forces in December 2016.

ISIL fighters are still thought to be present in several parts of southern and eastern Libya but no longer control any towns.

Migrant Crisis

The end of Gaddafi’s rule also meant the end of his security apparatus, which previously controlled trafficking routes through Libya.

Following the 2011 uprising, security has disintegrated and warring militias now operate along the long and porous desert and sea borders, making money by ferrying humans, gasoline, food, drugs and weapons.

Owing to Libya’s political divisions and the floundering economy, there are no facilities and desert patrols to tackle trafficking networks. There are also no funds for Libya’s coastguard to monitor sea crossings.

More than 150,000 people crossed through Libya in each of the past three years.

Libya’s proximity to the Italian island of Lampedusa and the closing of the EU-Turkey border has increased the flow of migrants entering Europe via the Libyan coast.

READ MORE: EU roadmap for Libya to stem flow of sea migrants

This year, around 26,886 migrants have crossed to Italy, over 7,000 more than during the same period in 2016. Since 2014, an estimated 11,221 people have drowned while taking the central Mediterranean route.

Recently, EU leaders agreed on a controversial new plan to stem the flow of migrants though Libya. They decided to give 200m euros ($215m) to Libya’s fragile government, so that it could increase efforts to stop migrant boats in the country’s territorial waters.

The plan also includes a promise from the EU to help set up “safe” refugee camps in Libya and assist refugees willing to return to their countries of origin.

Aid groups opposed the plan, saying it ignores the political reality in Libya, where the UN-backed government has only a partial hold on the country.

“Libya is not a safe place and blocking people in the country or returning them to Libya makes a mockery of the EU’s so-called fundamental values of human dignity and rule of law,” said Doctors Without Borders (known by its French initials, MSF), which works in camps there.

Recently, the International Organization for Migration (IOM) found that African migrants were being sold in Sabha, one of Libya’s smuggling hubs. The International Criminal Court has also decided to examine the possibility of an investigation into these markets.

Migrants are sold for $200 or $500 and are held on average for two to three months, Othman Belbeisi, head of the IOM’s Libya mission, said in Geneva.

“Migrants are being sold in the market as a commodity,” he said. “Selling human beings is becoming a trend among smugglers as the smuggling networks in Libya are becoming stronger and stronger.”

READ MORE: Refugee child abuse rampant in Libya – UNICEF

What is the situation today?

By 2016, a revised national unity government was installed. The 2015 negotiations suffered delays owing to opposing factions, who still refuse to sign on the proposed government.

The council that reached the agreement is made up of nine members from Libya’s rival factions and headed by Fayez al-Sarraj, the prime minister-designate.

After the political reshuffling, Libya’s current key players include the UN-backed Government of National Accord (GNA), led by Sarraj and based in Tripoli. The GNA includes the presidential council and since March 2016 has controlled ministries and government facilities in the capital.

The State Council, the advisory body of the GNA, is led by Abdulrahman Sewehli. Under the 2015 peace deal, some decisions are supposed to be agreed upon by both council and the HoR, which is supposed to serve as the unity government’s legislative body.

However, the HoR in Tobruk refuses to recognise the cabinet put forth by the presidential council and continues to rule its eastern stronghold. It is also allied with Haftar and his Libyan National Army, which also rules from Marj in the east.

Recently, Libya’s foreign minister announced at a news conference that Haftar will be appointed commander-in-chief of the Libyan army, on the condition that he accept the GNA as the governing authority.

The announcement was made a week after Haftar and Serraj met in Abu Dhabi. The meeting was intended to broker peace between the rival authorities, but no concrete document came out of the rare face-to-face conference.

However, both Serraj and Haftar released statements after the meeting promising to work together to end the conflcit in Libya.

Shortly after the meeting, 141 people were killed in an attack at an airbase in southern Libya that targeted armed groups loyal to Haftar. The attack could further escalate ongoing clashes in the south, as different militias and tribes vie for control of the smuggling routes.

The assembly tasked with writing the constitution has not yet completed the preliminary draft owing to constant setbacks.

“The conflict in Libya could be traced back to the parallel governments of Tripoli and Tobruk, even all the talks of ideological clashes and tribal rivalry are just an extension of the different governments vying for power,” Krikshi explained.