Lakshya

Software Engineering · Chapter 23 of 31

Git and GitHub, actually explained

Eight chapters on this site say 'pull request' as though you already know. This is the one that assumes you do not.

7 min read2 diagramsAll 31 chapters

If you have used git by copying commands off a colleague's screen and hoping, this chapter is for you. Nothing here is advanced. It is the set of ideas that everything else assumes.

Git and GitHub are not the same thing

THE FIRST THING TO GET STRAIGHT: THESE ARE TWO DIFFERENT THINGS GIT A program on your own computer. It records versions of your files, so you can look at what changed, and go back. Works with no internet and no account anywhere. Created in 2005. Free. Nobody owns your copy. Commands like commit, branch, merge are git. GITHUB A website that holds a shared copy, and adds things git does not have: a place to discuss a change, issues, permissions, and automation that runs when things happen. A company owns it. There are alternatives — GitLab, Bitbucket — and git works with all of them. push pull Why this matters, and it is not pedantry: a pull request is not a git command. It does not exist in git at all. It is a GitHub feature — which is why you will never find it ingit’s manual. SO WHEN SOMEONE SAYS “IT IS IN GIT”, ASK WHICH THEY MEAN “I committed it” means it is recorded on their laptop. “I pushed it” means it reached the shared copy. Those are different days of work. A great deal of confusion on teams is exactly this gap.
Getting this distinction straight fixes a surprising amount of confusion later — including why nobody can find the git command for a pull request.

Git is a program that runs on your machine and records versions of your files. It works with no internet connection and no account anywhere. GitHub is a website that holds a shared copy of a git project and adds the things git has no opinion about — a place to discuss a proposed change, issue tracking, who is allowed to do what, and automation that runs when something happens.

You can use git entirely on your own, forever, and never create a GitHub account. Plenty of people do.

The four words you need

WordWhat it actually isThe thing people get wrong
CommitA checkpoint you deliberately record, with a message saying whyIt is not the same as saving. Your editor saves; you decide when to commit
BranchA name for a line of work — technically just a label pointing at one commitIt is not a copy of your files. Creating one is instant and costs nothing, which is why teams make them freely
Push / pullSending your commits to the shared copy, and fetching other people's“I committed it” means it is on their laptop. “I pushed it” means it left. Those are different days of work
MergeJoining one line of work back into anotherA merge conflict is not an error. It means two people changed the same lines and git will not guess. It is asking you

The loop you will actually do

THE LOOP YOU WILL DO EVERY DAY, IN ORDER BRANCHname your lineof workCOMMITrecord acheckpointPUSHsend it tothe shared copyOPEN A PRask to merge,with a discussionREVIEWsomeone readsand commentsMERGEit joinsthe main lineDELETEtidy thebranch away AND THE THREE THINGS NOBODY EXPLAINS A BRANCH IS NOT A COPYIt is a movable label pointing atone checkpoint. Making one isinstant, and costs nothing.A COMMIT IS NOT A SAVESaving is your editor. A commit isa deliberate checkpoint with amessage explaining WHY.A CONFLICT IS NOT AN ERRORTwo people changed the same lines.Git refuses to guess, and asks you.It is normal, not a failure. THE COMMIT MESSAGE IS THE PART PEOPLE UNDERVALUE In two years somebody will run “why is this line here?” and get your message back as the only surviving explanation. Write why, not what. The diff already says what.
Seven steps, most of them one command. The three boxes underneath are the ideas people carry wrongly for years.
shellgit, and GitHub's own gh command-line tool
git switch -c fix-login-timeout     # make a branch and move onto it
                                    # ...edit files...
git add .                           # choose what goes in this checkpoint
git commit -m "Raise login timeout to 30s; the gateway was cutting us off"
git push -u origin fix-login-timeout

# then open the pull request — on the website, or:
gh pr create --fill

The commit message is worth more care than it usually gets. In two years somebody will ask why a line exists, run the command that shows who last changed it, and get your sentence back as the only surviving explanation. Write why you changed it. The diff already shows what you changed.

What a pull request actually is

A pull request is a request to merge one branch into another, wrapped in a page where people can discuss it line by line. It is not a git concept at all — git has no such command — which is exactly why you cannot find it in git's documentation. GitHub invented it; GitLab calls the same idea a merge request.

What it is for is the interesting part. Not gatekeeping. A pull request is the place where a change is explained to somebody who was not in your head when you wrote it, and where automated checks report before anyone spends attention. A good pull request description says what problem this solves and how you know it works. A bad one repeats the commit messages.

Keep them small, and the reason is measurable rather than stylistic.

A reviewer reading 40 changed lines finds real problems. The same reviewer facing 800 lines approves it, because the alternative is an hour they do not have. The review did not get harder — it stopped happening.

So if a change must be large, say so in the description and tell the reviewer what to look at first. And if you can split it, split it.

Actions, briefly

GitHub Actions runs commands automatically when something happens in the repository — most commonly, running the tests every time a pull request opens. It is a file in your project describing what to run and when:

yamlthe shape of a minimal workflow
# .github/workflows/test.yml
name: tests
on: [pull_request]          # run this whenever a PR is opened or updated

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4      # get the code
      - run: pip install -r requirements.txt
      - run: pytest

The point is not automation for its own sake. It is that a reviewer should never be the first thing to discover the tests fail. By the time a human looks, the machine should already have said whether it builds and passes.

Check yourself

What is the difference between git and GitHub?Git is a program on your machine that records versions and works offline. GitHub is a website holding a shared copy that adds discussion, issues, permissions and automation.
Why is there no git command for a pull request?Because it is not a git concept. GitHub invented it; GitLab calls the same idea a merge request.
Is a branch a copy of your files?No — it is a movable label pointing at one commit. Creating one is instant and costs nothing, which is why teams make them freely.
Is a merge conflict an error?No. It means two people changed the same lines and git refuses to guess. It is asking you to decide.
What should a commit message say?Why, not what — the diff already shows what. In two years it may be the only surviving explanation of why a line exists.
Why keep pull requests small?A reviewer facing 40 lines finds real problems; facing 800 they approve it. The review did not get harder, it stopped happening.
← Getting a password out of a vault, in codeYour editor, and putting a model in it →