All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
We do not know of any Sharee'ah impediment against borrowing in legal ways for the purpose of using it in charity if the borrower knows of himself the ability to pay the debt, and borrowing is essentially permissible for one who knows of himself the ability to pay it off, whether he borrows for the purpose of charity or for something else. The Encyclopedia of Jurisprudence reads: "The basic principle is that it is permissible, and that is for the one who knows that he will pay it off, if he has the money he hopes for, and is determined to pay it off, otherwise it is not permissible unless he was forced to."
The jurists have spoken about borrowing to carry out some acts to get closer to Allah. They said about the sacrifice. “And whoever lacks what to sacrifice with, he borrows, and sacrifices with the condition of being able to pay the debt.”
Therefore, there is no harm in you borrowing in order to dig a well for charitable purpose, provided that you know yourself the ability to pay it off.
Allah knows best.