GitHub intermediate
How do several people change one project without treading on each other? Branches and pull requests. A branch is a separate line of work.
Chapters
- 0:00Introduction
- 0:08A safe lane: What's a branch?
- 0:18Make one: A new branch
- 0:26Ask to merge: The pull request
- 0:37Good reviews: Make it easy
- 0:47Keep track: Use issues
- 1:00Stay current: Update your branch
- 1:07When lines clash: Merge conflicts
- 1:20Not your repo?: Branch or fork
- 1:30Interrupted?: Set work aside
- 1:39The merge button: Three ways to merge
- 1:52Wrap up
Read the transcript
Introduction
How do several people change one project without treading on each other? Branches and pull requests.
A safe lane: What's a branch?
A branch is a separate line of work. The main branch holds the shared version. Your branch holds your change while you build it. Main stays steady in the meantime.
Make one: A new branch
Create a branch and switch to it with git switch. Commit your work there as usual, then push the branch to GitHub.
git switch -c fix-login
git commit -am "Fix the login button"
git push -u origin fix-loginAsk to merge: The pull request
On GitHub, open a pull request. It shows exactly what your branch changes. Others read it and comment. When it's approved, merge it into main.
Good reviews: Make it easy
Help your reviewer. Keep the pull request small. Describe what changed, and how you tested it. New commits pushed to the branch join the same pull request.
Keep track: Use issues
Issues track bugs and ideas. Label them, and assign someone. Write closes, then the issue number, in a pull request description, and merging into the default branch closes the issue.
Stay current: Update your branch
Main moves while you work. Fetch the latest changes, and merge main into your branch.
git fetch origin
git switch fix-login
git merge origin/mainWhen lines clash: Merge conflicts
A conflict means two changes touched the same lines. Git marks both versions inside the file. Edit it to the result you want, and remove the markers. Then add the file, commit, and test.
Not your repo?: Branch or fork
If you can write to the repository, use a branch. If you can't, fork it: your own copy on GitHub. Then open a pull request from your fork.
Interrupted?: Set work aside
Need to switch jobs with half finished work? Git stash puts your changes safely to one side. Git stash pop brings them back.
git stash
git switch main
git switch fix-login
git stash popThe merge button: Three ways to merge
GitHub offers up to three ways to merge a pull request. A merge commit keeps every commit. Squash and merge turns them into one. Rebase and merge adds them one by one, with no merge commit.
Wrap up
Branch, push, review, merge. That's teamwork on GitHub.
Sources
- docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches
- docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests
- docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/about-merge-conflicts
- docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue
- docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks
- docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges
- git-scm.com/docs/git-stash
More lessons
- Docker advanced 2:44
- Docker networking 2:28
- GitHub basics 1:51
- GitHub advanced 1:59
- AI coding agents 1:18
- Software that runs models 1:15