The type of pages site you're using determines how your site redirects custom domains.

Warning: If the URL for your Pages site contains a username or organization name that begins or ends in a dash, or contains consecutive dashes, then people browsing with Linux will receive a server error when they visit the site. To fix this, change your GitHub username to remove non-alphanumeric characters. For instructions on how to do this, see "Changing your GitHub username."

Type of GitHub Pages site Pages default domain & host location on GitHub How the page is redirected Example custom domain
User Pages site username.github.io Automatically redirected to the custom domain that has been set for it user.example.com
Organization Pages site orgname.github.io Automatically redirected to the custom domain that has been set for it org.example.com
Project Pages site owned by a user account username.github.io/projectname Automatically redirected to a subdirectory of a User Pages site custom domain (user.example.com/projectname) project.example.com
Project Pages site owned by an organization orgname.github.io/projectname Automatically redirected to a subdirectory of an Organization Pages site custom domain (org.example.com/projectname) project.example.com

To learn more about the different GitHub Pages site types, including whether to use master or gh-pages as a publishing branch, see this User, Organization, and Project pages chart.