Why is the usage of " but" different in these two sentences? [closed]

That is because of what came before as the verb of the sentence. For the first sentence it is "did", and for the second it is "had".

So if you take out the middle part, the sentences become:

  1. He did (nothing at all but repeatedly) brag what he has done for the country.
  2. I had (no choice but) to give up the offer.