If you want to keep a pet from going up your stairs, you can certainly buy a commercial pet gate. But for a fraction of the price, you can assemble a rectangle using PVC and cover it with fabric.
Household weblog Sew Many Ways covers making this pet gate after the author's dog could no longer safely make it up the stairs. All that was needed was making a rectangle out of PVC pipe and elbow joints, and then covering that with whatever inexpensive fabric matches your home. You could also use this for a temporary baby gate, but I'd look for a more secure way to attach the gate to your stairs in that case.
Tool Time Tuesday: PVC Dog Gate and Stair Baskets Too! [Sew Many Ways]