Hi berkeokur
You cannot split the 3.5mm audio jack between a guitar and microphone or headphones and expect a decent recording. Guitars use a different impedance (electrical resistance or ohms) and need the proper electronic circuits for connection. This is much like a phonograph record player needing a pre-amp to hear the recording.
So for guitars, you need some sort of interface.
The 3.5mm port is an I/O port a.k.a. Input/Output so yes you can both input audio and export/listen at the same time. Headsets with mic works fine for example, just ask a gamer. You will need a TRRS cable to use this feature. This port has changed many times over the years so different Macs have different spec and abilities including optical, in some models.
The type of mic also matters. XLR mics will require an interface.
It is also possible to use a USB mic and use different port.
There are also guitar interfaces with USB plugs. I would look into a USB interface with guitar and XLR mic inputs with 48v phantom power for universal usage. They have gotten inexpensive and good these days.
Hope this Helps, Greg