John Hancock commissioned this portrait of George Washington by Charles Willson Peale after Washington liberated Boston from the British. (Spencer Platt/Getty Images)
Woody Holton, the McCausland professor of history at the University of South Carolina, is the author of the Bancroft Prize-winning “Abigail Adams” and a forthcoming reinterpretation of the American War of Independence.

The George Washington in “Hamilton” sings, “I wanna talk about what I have learned, the hard-won wisdom I have earned.” He’s not so different from the actual Washington, a hotspur at the start of the Revolutionary War who triumphed over the British only after learning to acknowledge his mistakes, seek counsel from experts and suppress his ego.

If those three traits sound unfamiliar in modern politics, they were critical for our first commander in chief. In some ways, we owe our country to Washington’s ability to evolve on matters of race, science and masculine pride. On this Fourth of July, President Trump could take note.

Washington’s first about-face, on race, came even before the first year of the war was out. And if it was more opportunistic than redemptive, it was still no small achievement for a large-scale slave owner. As many as 200 African Americans had fought valiantly in the opening salvos of the revolution, the Battle of Lexington and Concord and the Battle of Bunker Hill, both in mid-1775. But only a week after Washington took command of the Continental Army in July, he instructed recruiters not to enlist any more blacks. In October, he went further, ordering that all African American soldiers be driven from the lines.

Then events got ahead of him. Lord Dunmore, the last royal governor of Virginia, promised freedom to those who joined the British forces — publishing an emancipation proclamation similar to the one Abraham Lincoln would issue four score and seven years later, in that it applied only to slaves owned by rebels. Washington worried that the governor’s “Ethiopian Regiment” would “Increase as a Snow ball by Rolling.” One way to keep African Americans out of King George III’s army would be to allow them back into his own. Certainly Washington needed the manpower. Long-term service in the Continental Army was a job that most native-born whites were not willing to do.

There might have been an additional reason for a softening of Washington’s attitude toward blacks: some very admiring words from the enslaved poet Phillis Wheatley. “Fam’d for thy valour, for thy virtues more, Hear every tongue thy guardian aid implore!” she wrote in her poem “His Excellency General Washington.” As we all know, our national leaders can be suckers for flattery. Washington received the poem shortly before he recalled black soldiers to his army, and a couple of months later he thanked Wheatley in a letter: “I would have published the Poem, had I not been apprehensive, that, while I only meant to give the World this new instance of your genius, I might have incurred the imputation of Vanity.”

Regardless of Washington’s reasons, he reversed course, allowing free blacks — but not slaves — back into the Continental Army. That broke the dam, and soon recruiters in every state north of the Potomac were enlisting slaves as well. Even in Washington’s Virginia, about 500 slaves would serve in defiance of the official ban, mostly sent as substitutes for their owners.

Nearly twice as many black men who took up arms in the Revolutionary War fought for the redcoats as for the rebels. But by the war’s end, upward of 5,000 had enlisted with the Americans — about 5 percent of the army. Their crucial contributions (in 1778’s Battle of Rhode Island, for example, the mostly black Rhode Island 1st Regiment helped prevent the American retreat from turning into a rout) would have been lost if Washington had stuck with his earlier assumptions.

Washington’s second mid-war reversal involved another topic that has returned to the headlines in recent years: immunization. Continental soldiers were much more vulnerable to the deadly smallpox virus than were their enemies, most of whom had acquired immunity by surviving outbreaks in their more densely populated British and Hessian homelands. Continental Army doctors implored Washington to stop the dying by mass-inoculating his troops, but he had a very good reason for refusing. In this pre-vaccination era, the only way to inoculate patients against smallpox was to infect them with a mild case of the disease, immobilizing them for weeks. Washington feared that the British would discover his army’s temporary weakness and attack.

But as more and more American soldiers succumbed to smallpox, Washington finally relented, agreeing in early 1777 to initiate a program of mass inoculation. In “Pox Americana: The Great Smallpox Epidemic of 1775-82,” historian Elizabeth Fenn shows that by allowing the experts to change his mind, Washington saved his army.

Washington’s third transformation was both the slowest and the most important. It was also the most complex, since it involved his own ego. The 43-year-old Virginian entered the war hungering to command an epic assault on some entrenched enemy position, seizing independence for the United States in one grand struggle of gore and glory. He found the idea of cowering in fortifications humiliating. But over the next few years, he came to understand that his insistence upon playing offense might throw the war to the British.

On June 17, 1775, while the new commander in chief was in Philadelphia receiving his commission, a loose band of New England militiamen fought the redcoats at Bunker Hill. Gen. William Howe led the British, who finally captured the hill on their third try. The cost was heavy — almost half of his men were killed or wounded. Howe came away from the battle with a remarkable insight about his provincial opponents. “The intentions of these wretches,” he wrote, “are to fortify every post in our way; wait to be attacked at every one, having their rear secure, destroying as many of us as they can before they set out to their next strong situation.” Here was the British victor of the first major battle of the Revolutionary War declaring that it was the patriots’ war to win — so long as they stayed on defense.

Enter, with a flourish, George Washington. His first big initiative as commander in chief came on the night of March 4, 1776, when he had a detachment of Continentals secretly build two forts atop Dorchester Heights, south of Boston and just inside cannon range from there. Howe and his redcoats felt they had no choice but to evacuate New England’s largest town.

John Hancock was so pleased with Washington’s first great success that he commissioned a painting of him, and Harvard gave him an honorary degree. Astonishingly, though, Washington privately spoke of “the disappointment” he felt at how the Dorchester Heights affair turned out. He had not wanted to drive the British out of Boston but to trap and destroy them there.

In those days, Boston was almost an island; for instance, today’s tony Back Bay neighborhood was still an actual bay. For more than six months, Washington had pleaded with his council of war to approve an amphibious assault on the British garrison. But the redcoats had had ample time to ring Boston with heavily fortified entrenchments, and their battleships controlled the harbor. Rather than trying to storm the enemy’s fortifications, Gen. Horatio Gates wanted Washington to “leave it to them to give us the Advantage, by attacking Ours.”

Gates and the other generals approved Washington’s plan to occupy Dorchester Heights — but only because they figured Howe would feel compelled to send hundreds of redcoats charging up the heights to drive the rebels off, thus replaying his pyrrhic victory at Bunker Hill. Washington also counted on British troops ascending Dorchester Heights. But in his conception, that would be only the beginning. At that point, Howe would have depleted his Boston garrison, finally allowing Washington to launch his amphibious assault.

Howe disappointed Washington by decamping rather than fighting. He had been planning to leave Boston anyway, and the last thing he wanted was another Bunker Hill. After the British left, a chastened Washington toured the abandoned town, noting that it was “almost impregnable,” with “every avenue fortified.”

An American assault on Fortress Boston might have turned into a Bunker Hill in reverse, with mass casualties among the patriots and an invaluable public relations coup for the British. Washington was beginning to realize that he was not going to win the war with a grand assault against the serried ranks of redcoats. In fact, that might be the best way to lose it.

Instead, he would have to check his ego and stick to defense. That would not preclude the occasional surprise attack, such as his brilliant crossing of the Delaware River on Christmas night in 1776 to capture the Hessian garrison in Trenton, N.J. But it meant mostly retreating — in Faulkner’s words describing a later insurrection, walking “backward slow and stubborn.”

The current commander in chief catches hell for his acute sensitivity to criticism, and apparently the barbs only increase his insecurity. The case of George Washington suggests that the modern-day commentary should probably be framed more positively. The president might be reminded that the reason Washington has the tallest monument in the city that bears his name is that he learned to transcend his limitations. Most of all, he gained mastery over his aggressive instincts and fought a mostly defensive war.

He got glory by giving it away.

Read more from Outlook and follow our updates on Facebook and Twitter.