Remotes and GitHub
Forks and pull requests
Use a fork to propose work across repository boundaries and a pull request to review a branch before merging.
A fork is a repository hosted under another GitHub account. It gives you a place to push branches when you cannot or should not push to the original repository.
Suppose you forked someone’s notes-project on GitHub. Your local clone can keep both repositories as remotes:
git remote -v
You might see:
origin [email protected]:yourname/notes-project.git (fetch)
origin [email protected]:yourname/notes-project.git (push)
upstream [email protected]:flaviocopes/notes-project.git (fetch)
upstream [email protected]:flaviocopes/notes-project.git (push)
origin points at your fork. upstream points at the original. These names are conventions. Inspect the URLs instead of assuming.
A pull request asks maintainers to review and merge one branch into another. It is a GitHub collaboration feature, not a core Git command.
Before opening one, fetch the target repository and inspect your branch:
git fetch upstream
git switch add-search
git log --oneline upstream/main..HEAD
git diff upstream/main...HEAD
The commit range shows work reachable from your branch but not from upstream/main. The three-dot diff compares your branch with the merge base.
A realistic failure: your PR includes commits you did not mean to send. Maybe add-search was created from an old main and picked up unrelated history. The range command lists them:
abc1234 WIP experiment on ideas.txt
def5678 Add search to README
Rebase onto current upstream/main or recreate the branch with only the intended commits before opening the PR.
After you push to your fork’s origin, open the pull request on GitHub from yourname:add-search into flaviocopes:main. GitHub shows the same commit range you inspected locally.
If the PR looks empty, you probably compare against the wrong base branch. Switch the base to main on GitHub and refresh the diff.
Keep the pull request focused. Explain what changed, why, and how you tested it. Review comments may lead to more commits on the same branch. The pull request updates when you push them.
Try this before opening a PR: inspect upstream/main..HEAD. Can every listed commit and changed file be explained by one purpose?
Lesson completed