[This post is part of a larger strategy guide for Civilization 6]
In some ways, it does Civ 6 a disservice to try and consolidate everything about war into one large compilation. But there are so many one off tactical considerations that don't independently justify a full treatise, so here we are. I'll try and break things down into coherent subsections as much as possible. Also, this section is really only about land wars — they are by far the most common and most relevant kind of war, and there will be later pieces on nukes, planes, and boats.
Let's jump in.
Defense is better than offense
At a strategic level, it's of course better to be attacking an opponent than being attacked — if you can bring the fight to their territory, pillage their districts, and otherwise disrupt their game plan, that's good.
But at a tactical, unit to unit level, it's much better to defend. Mechanically, defenders get big combat bonuses, especially when fortified; as a result, a unit that doesn't have a ranged ability will on average take more damage from attacking than the unit that's being attacked. And of course, fortified defenders heal, which makes a one-on-one fight even more lopsided.
There's a bunch of important tactics that fall out of this:
To win any offensive war, you need to have an edge. Either your units are pound for pound stronger, or you have more of them. This is meant to offset the inherent advantage an attacker gets from deciding the when and where of an attack. Your strategic plan should account for this so that by the time you're actually in a fight, you've already won.
In a fight between two melee-only armies, it's strictly beneficial for a defense to set up a wall of units and fortify forever. However, because ranged units don't take damage from attacking, a single ranged unit can force opponents into moving troops.
Often, a fight will hinge on who can better protect their ranged units.
If you do have to attack an enemy unit, do enough damage to kill it outright. Enemy units healing is like paying interest on a loan — it builds up over time, until it's worth more than the original loan itself1.
Order of Operations
Civ gives bonuses for good positioning and penalties for being wounded. This means that there is an implicit order of operations that you should follow to get the most damage output on a given turn.
Start by positioning as many units as possible around the opponent unit that you want to attack. Each additional unit will give you a flanking bonus. Due to their high movement, scouts and cavalry are especially good for this.
Next, attack with your ranged units. These will wound enemies, lowering their combat score.
Finally, if you are not planning to fortify/defend, you can attack with your melee units, in order from strongest to weakest (to offset your own damage penalties).

Note that you may not want to always finish an opponent off with a melee unit — doing so will cause your unit to move forward, potentially breaking formation.
Quickly responding to a surprise war
Someone declared war on you, totally unexpectedly. You haven't built a unit in a while, you don't have walls. At least one of your cities is directly under attack, possibly under siege. What's the best course of action?
Your immediate goal is to staunch the bleeding and save the threatened city. The name of the game here is to delay as long as possible so you can get your shit together.
Start by cursing your opponent out in the voice chat.
If you have him, move Governor Victor to whichever city is about to face the brunt of the attack.
Start building walls in the three or four closest cities, ranged units in other nearby cities, and cavalry in your farther cities.
Depending on which era the attack occurs, switch to researching steel (free walls in all cities) or the next unit upgrade (e.g. crossbows if you're currently on archers, or pikemen if you're currently on spears).
City strength is determined by the strongest melee, anti-cavalry, cavalry, or naval-melee unit that you've ever built. Get as much gold as you can, potentially by trading with other players, to buy the strongest unit you have access to2. It does NOT have to be in the city being attacked, though if it is that city gets extra defense.
City ranged strength is based on the strongest ranged, siege, or naval ranged unit you've created. If you have enough funds to spare, buy the strongest ranged unit you can in the city that is being attacked (if you didn't already buy a melee unit there) or in the nearest city.
Switch to researching whichever civic that will finish fastest so that you can unlock a change in policy cards.
As soon as you can change your policies, slot in Limes (+50% to walls), Bastions (+6 city defense strength, +5 city ranged strength), and any other cards that can boost production or coin. Obviously, switch governments if that makes sense and is available.
If you're deciding on your next civic, go for one that gives you a governor promotion so you can either pick up Victor, or get Victor's "Garrison Commander" (+5 to units defending in the city) or "Embrasure" (city gets a second ranged attack) promotions.
On your next few turns, try and make sure your city is not put under siege so it can continue healing each turn. If you have any units at all, place them opposite rivers near your city and attack the weakest melee or siege units.
This is the best you can do to slow an attack. Hopefully, you're not caught entirely with your pants down and you have some existing units or coin saved.
Once you have walls up, the defense plan changes a bit — now your aim is to kick out the invaders.
If you haven't yet, get a ranged unit in the city that's under attack and start doing double damage to any attackers (from the ranged unit and from the walls). Prioritize attacking siege.
Start building an encampment in the city that's under attack. The encampment should be between the city and the border towards where your opponent is attacking from. Keep it within two tiles instead of the possible three3.
Some of the units that you were building in your nearby cities should start finishing. Move them into position, around the threatened city, again focused on killing siege.
The encampment serves two purposes. First, it gives you another set of ranged attacks to do each turn, both from walls and from another ranged unit. Second, it prevents your opponent from moving more units in, creating a natural barrier between enemy units near the city and support units on the outside.
Once you can establish a defense perimeter and can guarantee that your city is not under significant attack, switch your farther cities back to building infrastructure. Continue researching unit upgrades to improve your cities' ranged and defense strength. Hold the line until you can get a peace deal.
It's tempting to counter attack immediately. It's rarely a good idea. Unless your opponent is way behind and has no army, you likely don't have a very strong edge (stronger units, many more units) to justify an attack. I generally recommend pulling back to set up the next timing push.
This is especially true if your opponents can get promotions as a result of your attacks. You have to kill them before they can activate the promotion.
You should always have enough gold to buy or upgrade to the next level unit for this reason.
Note: every time your opponent places a unit on this tile, it will stop building. Be sure to remember to swap back to building the encampment whenever it's free to build.