You probably misused
sudo during an earlier update/branch switch.
sudo on OctoPi unless you need to restart the OctoPrint service or are explicitly instructed to do so.
That means no
sudo git ..., no
sudo ~/oprint/bin/python ... etc. The only thing your need sudo for usually is
sudo service octoprint restart.
If you get a permission error, you broke your file system permissions by using
sudo wrongly. Yes, you could just ignore this and use
sudo with everything from now on, but that will break things. Instead you need to fix those file system permissions (and in order to do this you do need
sudo chown -R pi.pi ~/oprint ~/OctoPrint
After that, updating/switching branches and installing plugins should work without permission errors.