A US federal judge has ruled that the ban on gay soldiers serving openly in the military violates the US constitution.

US District Judge Virginia Phillips said yesterday she would issue an injunction barring the government from enforcing the policy.

Currently, gay soldiers must keep their sexual orientation secret or risk being fired.

The case was brought against the government by the Republican party’s gay group, the Log Cabin Republicans.

Judge Phillips said the Justice Department would have the opportunity to appeal against her ruling.

This means that the Obama administration will have to defend the law while the president is pushing Congress to repeal it.

Government attorneys argued that the issue should be decided by Congress, not a federal courtroom.

President Obama promised to repeal the law in his 2008 election campaign but has been accused of stalling on the issue by gay rights groups.

A Pentagon review of the policy is underway and the government has said changes will not be made until it is complete.

Opponents to lifting the ban say it will harm recruitment and morale but Judge Phillips wrote that its restrictions “actually serve to impede military readiness and unit cohesion rather than further these goals”.

An estimated 13,500 people have been discharged since the policy came into effect in 1993.