When you march out to battle your enemies and you see horses, chariots, and a fighting force larger than yours, don't be afraid of them, because the LORD your God, the one who brought you up from Egypt, is with you.
References for Deuteronomy 20:1
As you advance toward the war, the priest will come forward and will address the troops.
He will say to them: "Listen, Israel: Right now you are advancing to wage war against your enemies. Don't be discouraged! Don't be afraid! Don't panic! Don't shake in fear on account of them,
because the LORD your God is going with you to fight your enemies for you and to save you."
The officials will also say to the troops: "Is there anyone here who has just built a new house but hasn't yet dedicated it? He can leave and go back to his house; otherwise, he might die in the war and someone else would dedicate the house.
Or is there anyone here who has planted a vineyard but hasn't yet put it to good use? He can leave and go back to his house; otherwise, he might die in the battle and someone else would use the vineyard.
Or is there anyone here who is engaged but not yet married? He may leave and go back to his house; otherwise, he might die in the battle and someone else would marry his fiancée."
The officials will continue to address the troops, stating: "Is there anyone here who is afraid and discouraged? He can leave and go back to his house; otherwise, his comrades might lose courage just as he has."
Once the officials have completed their speech to the troops, the army commanders will assume leadership of the forces.
When you approach a city to fight against it, you should first extend peaceful terms to it.
If the city responds with peaceful terms and surrenders to you, then all the people in the city will serve you as forced laborers.
However, if the city does not negotiate peacefully with you but makes war against you, you may attack it.
The LORD your God will hand it over to you; you must kill all the city's males with the sword.
However, you can take for yourselves the women, the children, the animals, and all that is in the city—all its plunder. You can then enjoy your enemies' plunder, which the LORD your God has given you.
That's what you must do to all the cities that are located far away from you—specifically, those cities that don't belong to these nations here.
But in the case of any of the cities of these peoples—the ones the LORD your God is giving you as an inheritance—you must not spare any living thing.
Instead, you must place these under the ban: Hittites, Amorites, Canaanites, Perizzites, Hivites, and Jebusites—just as the LORD your God commanded you.
References for Deuteronomy 20:17
Then they can't teach you to do all the detestable things they did for their gods, with the result that you end up sinning against the LORD your God.
Now if you have been attacking a city for some time, fighting against it and trying to conquer it, don't destroy its trees by cutting them down with axes. You can eat from those trees; don't cut them down! Do you think a tree of the field is some sort of warrior to be attacked by you in battle?
That said, if you know that a tree is not a food-producing tree, you are allowed to destroy it, cutting it down and using it in the siege against the city that is fighting against you until it falls.