Skip to content

Sign in to GitHub

This page is part of step 5 of the path, the sign-ins. sfe reads GitHub (pull requests, commits and the code of our repositories) through gh, GitHub's own command line program, so it needs gh to be signed in as us. If we sign in before step 3, sfe start also finds our GitHub account and organisation by itself. We type our password in the browser page gh opens, never in Terminal. It takes about five minutes.

Video, about one and a half minutes, with narration and captions.

The video shows sfe's own checks for this sign-in, from a real run. The browser part of a sign-in, where we type our password and approve it, is ours alone, so the video describes it and does not record it.

Before you start

  • Before you begin is done, and a Terminal window is open.
  • We have a GitHub account. If not, we make one at github.com first.
  • Our GitHub account can see our team's repositories. Step 4 below checks it.
  • gh is installed. Step 1 checks it.

Steps

1. Check that gh is on the Mac

gh --version

The Mac prints a line that starts with gh version. If it says command not found: gh, we install it with Homebrew:

brew install gh

If brew is also missing (step 2 of Before you begin showed that), we install Homebrew first. The command is on the front page of https://brew.sh. It asks for our Mac password once, and it can take several minutes.

2. Sign in

gh auth login

gh asks a few questions. We choose these answers with the arrow keys and Enter:

Question Our answer
Which account to log into GitHub.com
The preferred protocol for Git operations HTTPS
Authenticate Git with our GitHub credentials Yes
How to authenticate Login with a web browser

The words may read a little differently in a newer version of gh. gh then prints a one-time code made of eight characters, and says to press Enter to open github.com in the browser.

3. Finish in the browser

We press Enter. The browser opens a GitHub page. We type the one-time code from Terminal into it, and sign in to GitHub if it asks. We type our password and our verification code there, in the browser. Nothing we type in the browser goes through Terminal.

If the repository belongs to an organization that uses single sign-on (one company login for many tools), the page may show a button to authorize the token for that organization. We click it.

Back in Terminal, gh prints a line that starts with a tick, such as Authentication complete, and says which account we are logged in as. gh keeps the login in the Mac's own secure store, the login Keychain, so we do not sign in again each time.

4. Check the sign-in and the access

gh auth status

It prints Logged in to github.com and our account name. gh auth status: logged in to github.com, the account, and the token shown as stars

Then we ask GitHub to show one repository our team works in, giving its owner and name:

gh repo view <owner>/<repository>

A short description of the repository, with its README, means we have access. If it says that it could not resolve the repository, our account cannot see it yet, and we ask our team lead to add our GitHub username. Both commands only read.

sfe checks the same login from its side:

sfe doctor github

sfe doctor github: the GitHub login, with the account name

What we should see

  • gh --version printing a version.
  • Logged in to github.com from gh auth status.
  • The repository's description from gh repo view.

Troubleshooting

What we see Likely cause What to do
command not found: gh gh is not installed brew install gh, or install Homebrew first if brew is missing too
The one-time code is refused, or has expired It lasts a few minutes only Run gh auth login again for a new code
gh auth status says we are not logged in The sign-in did not finish Run gh auth login again, and finish the browser page
Could not resolve to a Repository Our account cannot see that repository We ask our team lead to add our GitHub username, then run the command again
The browser shows a page about organization access The organization uses single sign-on We click the button that authorizes gh for the organization

Next


Last reviewed: 2026-12-02