The basic phrasing for the modern allegiance pledge to America was created by a Baptist minister named Francis Bellamy in 1892. His twenty-three word vow, crafted to be brief so that it could be recited quickly, is the following.
"I pledge allegiance to (promising to uphold the basic principles symbolized by) my flag and to the Republic for which it stands - one Nation, indivisible, with liberty and justice for all"
After a few minor changes over the years, the modern Pledge was approved by the U.S. Congress and signed into law in 1954 by then President Eisenhower.
Flags
The first issue we will tackle concerns flags. Are they, of themselves, wrong to create (let alone pledge to) in the eyes of God? Is there existence idolatrous and contrary to the second commandment (Exodus 20:4 - 5), especially when they are created to represent a group of human beings?
God, a short time after giving the Ten Commandments on Mount Sinai, told the children of Israel to do the following.
And the Lord spoke to Moses and to Aaron, saying, "Every man of the children of Israel shall pitch by his own banner (or standard to denote a particular tribe) . . . " (Number 2:1, HBFV throughout).
The Hebrew word translated as "banner" in the above verse is degel, Strong's Concordance #H1714, which means a flag or a standard. They were used not only to represent an individual Israelite tribe but also a group of tribes.
For example, the flag of Judah represented the three tribes of Judah, Issachar and Zebulon that were located on the eastern side of Israel's wilderness encampment after they left Egypt (Numbers 2:3 - 9). The flags of Ephraim, Reuben and Dan also represented a collection of three tribes (verses 10 to 31).
The commandment
The second commandment, which concerns idolatry, states that we are not to make anything that resembles what God has already made in order to bow down and worship it (Exodus 20:4 - 5). Only the true God is worthy of worship.
Notice that the focus of the commandment is not to forbid using creativity to make things patterned after something that already exists. The commandment forbids making things with the intent to use them to divert, dilute or otherwise pervert worship and obedience that rightfully belongs to God. It does not forbid making flags that symbolize nations, territories, etc.
The Bible teaches that we should voluntarily pledge to obey the laws of men and even render honor to those who are in positions of authority (Romans 13:1, 5).
Read carefully, the Pledge of Allegiance encourages those who say it to respect and uphold what America stands for, but it places such loyalty to "one nation" not above, but rather subservient to (through the phrase "under God"), the Eternal's authority.
There is nothing wrong with expressing loyalty toward and obedience to a country or cause so long as what is required does not conflict with fully worshipping God and obeying his law and their intent.
In general, it is not idolatry to say a pledge of allegiance to a flag. Christians are not duty bound to obey any command or edict from any governmental, religious or other authority that conflicts with God's will.