2 wire bus without libary

The SPI bus has a chip select, when that becomes active the data and clock starts.

Your code is a little confusing to me. I think that once the bits are out of sync, there is no way to make them go back into sync.

The 595 can be used with the function shiftOut(): https://www.arduino.cc/en/Tutorial/ShiftOut.

bitWrite() can set a bit in a variable to 0 or 1.
Did you read the reference ?
See the "Bits and Bytes" section: Arduino Reference - Arduino Reference

To stay in sync you need a start signal. Or you need a special protocol for the bits, perhaps even with a checksum.
To avoid specific timing, you need two handshake signals.