| <- Previous: Learn Remotes And Cloning | Next: Troubleshooting -> |
|---|
Know when to use a branch, when to use a fork, and what origin and upstream mean in a fork-based workflow.
- explain the difference between a branch and a fork
- identify when
originpoints to your fork - add the original repository as
upstream
- A branch is a pointer inside one repository.
- A fork is a separate repository created on GitHub under another account or organization.
- In a fork workflow,
originusually points to your fork andupstreampoints to the original repository.
For the main course flow, you do not need a fork. Because this repo is a template, your personal copy already gives you a safe place to practice branches and pull requests.
Use a branch when you already have write access to the repository and want to isolate work from main.
That is the default workflow for this course once you create your own copy from the template.
Example:
git switch -c feature/profile-pageUse a fork when you do not have direct write access to the original repository, or when a project expects contributions through personal copies.
Typical flow:
- fork the repository on GitHub
- clone your fork
- add the original repository as
upstream - push your work to your fork
- open a pull request back to the original repository
Clone your fork:
git clone git@github.com:your-username/the-forked-repo.git
cd the-forked-repoAdd the original repository as upstream:
git remote add upstream git@github.com:original-owner/the-repo.gitFetch updates from the original repository:
git fetch upstreamRun:
git remote -vExpected output includes both remotes:
origin git@github.com:your-username/the-forked-repo.git (fetch)
origin git@github.com:your-username/the-forked-repo.git (push)
upstream git@github.com:original-owner/the-repo.git (fetch)
upstream git@github.com:original-owner/the-repo.git (push)
- You can explain why a branch stays inside one repository while a fork creates a second repository.
- You can explain what
originandupstreameach point to in a fork workflow. - You can explain why this course uses a template copy plus branches instead of asking every learner to work in the academy repository.
- You can add
upstreamwithout deletingorigin.
| <- Previous: Learn Remotes And Cloning | Next: Troubleshooting -> |
|---|