Learn / Lessons · GitHub

GitHub advanced

Ready to let GitHub test your work, guard your main branch, and help you undo mistakes? GitHub Actions runs jobs for you.

Chapters

  1. 0:00Introduction
  2. 0:06Automation: GitHub Actions
  3. 0:18Where it lives: A tiny workflow
  4. 0:29Keys: Handle secrets
  5. 0:42Guard main: Protect your branch
  6. 0:52Tidy history: Merge or rebase
  7. 1:04Oops: Undo safely
  8. 1:13Find the break: Bisect the bug
  9. 1:23Publish: Tags and releases
  10. 1:31Watch your back: Let GitHub watch
  11. 1:46Rescue: Find lost commits
  12. 1:55Wrap up
Read the transcript

Introduction

Ready to let GitHub test your work, guard your main branch, and help you undo mistakes?

Automation: GitHub Actions

GitHub Actions runs jobs for you. An event, such as a push or a pull request, starts a workflow. Its jobs run on a machine called a runner, one step at a time.

Where it lives: A tiny workflow

Workflows live in the .github/workflows folder. This one runs on every pull request. It checks out the code, then runs your tests.

# .github/workflows/test.yml
on: [pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: ./run-tests.sh

Keys: Handle secrets

Workflows often need keys. Store them as encrypted secrets, never in the file. Give each workflow only the permissions it needs. And be careful with third party actions: pin them to a full commit.

Guard main: Protect your branch

Branch protection rules and rule sets guard main. Require a pull request, require an approving review, and require the tests to pass.

Tidy history: Merge or rebase

A merge joins two histories and keeps both. A rebase replays your commits on top of another branch. It rewrites them, so avoid rebasing work others share.

Oops: Undo safely

To undo a commit that's already shared, revert it. That adds a new commit which reverses the old one. History stays honest.

git log --oneline
git revert 1a2b3c4

Find the break: Bisect the bug

When something broke and you don't know when, use git bisect. Mark a bad commit and a good one. Git checks out the middle, you test it, and it narrows down the culprit.

git bisect start
git bisect bad
git bisect good v1.0.0

Publish: Tags and releases

A tag names one exact commit. Push the tag to GitHub, and publish a release with notes and downloads.

Watch your back: Let GitHub watch

GitHub can watch your repository for you. Dependabot can raise pull requests that update risky dependencies. Secret scanning looks for keys that slipped in. And a code owners file asks the right people to review.

Rescue: Find lost commits

Thought you lost a commit? Git keeps a local diary called the reflog. Find the commit in the list, then start a new branch from it.

git reflog
git switch -c rescue 9f8e7d6

Wrap up

Automate the checks, protect main, and release with care.

Sources

More lessons