Showing the gluability of sheaves I'm trying to prove that sheaves on the elements of an open cover glue into a sheaf on the whole space. Precisely, I'm following the Stacks project and trying to prove the proposition below.

I began as follows:

The collection $\mathcal{B}$ of the open sets $U\subset X$ which are contained in one of the $U_i$ forms a base for the topology of $X$. If $U\in\mathcal{B}$, we define a sheaf on $\mathcal{B}$ by setting $F(U)=\mathscr{F}_i(U)$ whenever $U\subset U_i$. The isomorphisms $\varphi_{ij}$ shows that this is independent of the choice of $i$. The restriction maps come from those of $\mathscr{F}_i$. Also, the fact that $\mathscr{F}_i$ is a sheaf implies that indeed $F$ is a sheaf on $\mathcal{B}$. This extends to a sheaf $\mathscr{F}$ on $X$.

Now, I need to prove that there exists the said isomorphisms that make diagram commute. Indeed, since $\mathscr{F}$ coincides with $F$ whenever $U\subset U_i$, we have an isomorphism of sheaves $\mathscr{F}|_{U_i}\to \mathscr{F}_i$. I just don't know how to show that the said diagram commutes. I surely have to use the cocycle condition, since it wasn't used yet, but I don't know how.
PS: I did in fact read all the related answers in MSE but none tries to prove this result using a base of open sets, so they weren't helpful.
 A: This is not a complete answer but too long for a comment.

If $U\in\mathcal{B}$, we define a sheaf on $\mathcal{B}$ by setting $F(U)=\mathscr{F}_i(U)$ whenever $U\subset U_i$. The isomorphisms $\varphi_{ij}$ shows that this is independent of the choice of $i$.

I think already this is not quite precise enough to be able to finish the problem.
In fact the group $F(U)$ very much depends on the choice of $i$ (e.g. imagine that the elements of $\mathscr{F}_1(U)$ are red and the elements of $\mathscr{F}_2(U)$ are blue. What color are the elements of $F(U)$?) It is the isomorphism class of group that doesn't depend on the choice of $i$ -- but specifying an isomorphism class of group for each $U$ isn't enough to define a (pre)-sheaf.
Normally one wouldn't get too worked up about such pedanticness, but in this problem the pedanticness is the point, since you have to keep track of the isomorphism in order to check the commuting diagram.
A: I couldn't make @RaviFernando's idea work but the heuristic of "trying to make all possible choices" worked. (I think...)

(Theorem 19.5.1 is the fact that sheaves on a base can be uniquely extended to "normal" sheaves and proposition 19.5.3 is the fact that the sheaf hom is indeed a sheaf.)
I would love to have some feedback about my answer and I would really like to see how @RaviFernando's idea would work.
