Fixed order of operations in sync
Fixed bug inolving checkout during not clean git state.