Shearing dynamics of magnetic arches and formation of prominences