How to use withcredentials syntax in shared library groovy script

Can anyone help me how to use the git credentials using a shared library concept in groovy script using withCredentials method and how to call in another shared library groovy file.