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

Track 05 · Working as a team with Git

Starting work

Lesson 2 of 7· 6 min

Get the code once, then start every piece of work on a fresh branch made from the latest shared code. Most painful merge conflicts begin right here, with a branch started from an old copy.

Fresh or stale?

Let teammates merge, then start a branch

develop on GitHub

The real thing. Teammates merge here.

  1. 2c1d0e9
  2. 8a7b6c5

origin/develop

Your laptop’s copy of GitHub’s. Updated by git fetch.

  1. 2c1d0e9
  2. 8a7b6c5

develop (local)

Your own branch. Updated by git pull.

  1. 2c1d0e9
  2. 8a7b6c5

Now start your branch from…

Merge a teammate’s PR or two, then try each way of starting a branch.

Three copies of the same branch#

There are three versions of the target branch in play: the real one on GitHub, your laptop's copy of GitHub's (origin/develop), and your own local branch (develop). Teammates merge into the first one all day. The other two only change when you ask: git fetch updates your copy of GitHub's, and git pull updates both.

That's why a branch made from your local develop can start days behind. Either git pull first, branch from origin/develop right after a git fetch, or let gh issue develop create the branch on GitHub itself.

Get the team's repo on my laptop#

When: You need the code for a project for the first time.

$ gh repo list your-org
1/5

Not sure of the exact repo name? List everything in the organization.

Commands to copy

  • $ gh repo list your-org

    Find the repo name

  • $ gh repo clone your-org/app

    Download it

  • $ cd app

    Go into the folder

I was assigned an issue. Where do I start?#

When: Your lead assigned you a ticket on GitHub.

$ gh issue list --assignee "@me"
1/6

"@me" means you. Keep the quotes, they matter in PowerShell.

Commands to copy

  • $ gh issue list --assignee "@me"

    My issues

  • $ gh issue view 42

    Read one

  • $ gh issue develop 42 --checkout --base develop

    Branch for it, linked to the issue

  • $ git switch -c feat/signup-fix origin/develop

    Or: make a branch with your own name (plain Git)

Check yourself

You ran git switch -c feat/x develop without pulling for a week. What's the likely problem?