How does GitHub know when to send a git repo or a web page?

How does GitHub know when someone is trying to clone a repo and how does it know when someone is just accessing the web page for it?

Is this something that can be done in Apache or nginx?


This is the git “smart http” protocol. Some relevant background to read: here and here. The latter mentions Apache configuration stuff.

Without digging into the details, I’d assume that the HTTP requests are different. [Browser request vs git application request] If I wanted to know more, I’d use something like fiddler to examine the network traffic.


When you run git clone, the http request sent by git is actually GitHub handles it by calling git instead of serving html.

Try it: open the above link (or use any other public repo) in your browser (or curl) and see what you get back.

So I could create a system like GitHub by returning the refs file for a request too and the HTML file for a request to