This is an especially humorous English phrase because of the word “bark” being used in the same phrase with the word “tree.” While “bark” is a word for the outer layer of a tree, the “barking” here actually refers to the action of a dog barking. When a dog chases a squirrel or similar animal that runs up a tree, a dog occasionally chooses the wrong tree to bark at.
A person may also conceptually choose a tree or path that is not as effective as another for what the person wants to accomplish.
For Example:
“He was barking up the wrong tree when he tried to use a screwdriver with nails.”