merge branch algo