We analyze the interplay between charge-density-wave (CDW) orders with axial momenta (Q, 0) and (0, Q) (∆x and ∆y respectively), detected in the underdoped cuprates. The CDW order in real space can be uni-directional (either ∆x or ∆y is non-zero) or bi-directional (both ∆x and ∆y are non-zero). To understand which of the two orders develop, we adopt the magnetic scenario, in which the CDW order appears due to spin-fluctuation exchange, and derive the Ginzburg-Landau action to the sixth order in ∆x and ∆y. We argue that, at the mean-field level, the CDW order is bi-directional at the onset, with equal amplitudes of ∆x and ∆y, but changes to uni-directional inside the CDW phase. This implies that, at a given temperature, CDW order is uni-directional at smaller dopings, but becomes bi-directional at larger dopings. This is consistent with recent x-ray data on YBCO, which detected tendency towards bi-directional order at larger dopings. We discuss the role of discrete symmetry breaking at a higher temperature for the interplay between bi-directional and uni-directional CDW orders and also discuss the role of pair-density-wave (PDW) order, which may appear along with CDW. We argue that PDW with the same momentum as CDW changes the structure of the bi-directional charge order by completely replacing either ∆x or ∆y CDW components by PDW. However, if an "Amperean" PDW order, which pairs fermions with approximately the same momenta, is also present, both ∆x and ∆y remain non-zero in the bidirectional phase, albeit with non-equal amplitudes. This is again consistent with x-ray experiments, which at larger doping found non-equal ∆x and ∆y in every domain.