Track 05 · Lesson 1 of 7Working as a team with Git

Track 05 · Working as a team with Git

Setting up

Lesson 1 of 7· 6 min

This track is a playbook for working on a real team with Git and the GitHub CLI, gh. Each lesson is a stage of a normal week, and each section is a real situation: the exact commands, what the terminal prints back, and the mistakes to watch for. Start here, on day one.

Before we start: your setup#

Every command in this track uses example names: a repo, a branch, a target branch, a PR number. Type your own team's values here once, and every command on every lesson in this track fills in with them, ready to copy. Leave them as they are if you're just learning.

Your setup

Every command in this track updates as you type

Two identities, one laptop

Switch each setting and watch what changes

gh acts as

Changed with gh auth switch. Decides what you can see and do on GitHub.

Git signs commits as

Changed with git config user.email. Decides the name on every commit.

$ gh repo list your-orgno repositories found for your-org
$ git commit -m "fix: handle empty email"$ git log -1 --format='%an <%ae>'You <you@gmail.com>

gh is logged in as your-personal-account, which isn’t in your-org, so the company repos are invisible.

Your commits in the company repo carry your personal email, even when gh is on the work account.

gh and Git are different tools#

Git is the version-control program on your laptop: commits, branches, merges. GitHub is the website that hosts the shared copy. gh is GitHub's command-line tool: it opens PRs, reads issues and checks CI without leaving the terminal.

They each have their own idea of who you are. gh auth login decides which GitHub account gh acts as, so it decides which repos you can see. git config user.email decides the author on every commit you make. Fixing one doesn't fix the other, which is why the demo above has two switches.

First day: set up gh on my laptop#

When: You just joined the team or got a new laptop.

$ gh auth login
1/7

Run this once after installing. It connects gh to your GitHub account.

Commands to copy

  • $ winget install --id GitHub.cli

    Install on Windows. On macOS: brew install gh

  • $ gh auth login

    Log in (the walkthrough above)

  • $ gh auth status

    Check who you are logged in as

  • $ gh config set editor "code --wait"

    Optional: write PR descriptions in VS Code

I have a work account and a personal account#

When: gh is acting as the wrong person, for example you can't see the company repos.

$ gh auth status
1/5

Type this and press Enter.

Commands to copy

  • $ gh auth status

    Who am I logged in as?

  • $ gh auth login

    Add a second account (same steps as first-day setup)

  • $ gh auth switch

    Switch between accounts

Check yourself

gh is logged in to your work account, but your commits in the company repo show your personal email. Why?