There are (at least) two ways to do this.
One way is by using transition functions. Let $\{U_\alpha\}$ be an open cover of $M$ such that $P$ is trivial over each $U_\alpha$, and let $\tau_{\alpha\beta}\colon U_\alpha\cap U_\beta \to G$ be the corresponding transition functions. Define new transition functions $\sigma_{\alpha\beta}\colon U_\alpha\cap U_\beta\to H$ by $\sigma_{\alpha\beta} = f\circ\tau_{\alpha\beta}$. These satisfy the cocycle condition: For all $x\in U_\alpha\cap U_\beta\cap U_\gamma$, $\sigma_{\alpha\beta}(x)\sigma_{\beta\gamma}(x) = \sigma_{\alpha\gamma}(x)$ (which follows from the cocycle condition for $\{\tau_{\alpha\beta}\}$), and thus can be used to construct a principal $H$-bundle $\widetilde P\to M$ that is trivial over each $U_\alpha$ and has $\{\sigma_{\alpha\beta}\}$ as transition functions. (The construction goes like this: Start with the disjoint union of the trivial bundles $U_\alpha\times H$, and then take the quotient by the equivalence relation generated by declaring $(x_\alpha,h_\alpha)\in U_\alpha\times H$ equivalent to $(x_\beta,h_\beta)\in U_\beta\times H$ if $x_\alpha=x_\beta\in U_\alpha\cap U_\beta$ and $h_\beta = \tau_{\alpha\beta}(x_\alpha)h_\alpha$. This is what Yuan was referring to when he mentioned Čech cocycles.) Given a $G$-bundle morphism $\Phi\colon P\to P'$ covering a map $\phi\colon M\to M'$, we can define an associated $H$-bundle morphism $\widetilde \Phi\colon \widetilde P\to \widetilde P'$ by $\widetilde\Phi[x_\alpha,h_\alpha] = [\phi(x_\alpha),f(h_\alpha)]$, where the brackets represent equivalence classes. This yields a functor $P\mapsto \widetilde P$, $\Phi\mapsto \widetilde \Phi$.
A more invariant way to do it is based on the associated bundle construction. Define an equivalence relation on $P\times H$ by
$$
(p,h) \sim (pg^{-1}, f(g)h), \qquad g\in G,
$$
and let $\widetilde P$ be the quotient space of $P\times H$ under this equivalence relation. For each $(p,h)\in P\times H$, let $[p,h]$ denote its equivalence class in $\widetilde P$. There is a well-defined projection $\widetilde \pi\colon \widetilde P\to M$ given by $\widetilde \pi[p,h] = \pi(p)$, whose fibers are homeomorphic to $H$. There is a right action of $H$ on $\widetilde P$ given by $[p,h]\centerdot h' = [p,hh']$, which is easily seen to be well-defined, free, and transitive on fibers. This turns $\widetilde P$ into a principal $H$-bundle over $M$. For any $G$-bundle morphism $\Phi\colon P \to P'$, the associated $H$-bundle morphism $\widetilde \Phi\colon \widetilde P\to \widetilde P'$ is defined by $\widetilde \Phi[p,h] = [\Phi(p),f(h)]$.