Opening a PR
- Git course
- Intermediate
- Lesson 50/82
- 4 min
Learn to push a branch and open a PR on GitHub.
Push the branch before opening a PR
To open a PR on GitHub, your working branch must exist in the remote repository. First push your branch using git push -u origin feature-login. This command uploads the branch and establishes an upstream connection between the local and remote branches.
git switch -c feature-login
git add login.js
git commit -m "Add login feature"
git push -u origin feature-loginAfter pushing the branch, you can compare it with the target branch on GitHub and create a PR.
Creating a PR on GitHub
After pushing your branch, open the Pull requests section of the GitHub repository and select New pull request. Choose the target branch in Base and the source branch in Compare. After GitHub displays the changes, add a title and description and select Create pull request.
Base: main
Compare: feature-login
Title: Add login featureThe comparison screen lets you check which files have changed and what modifications were made.
Practice Push a branch for a PR
Push the local branch named feature-search to the origin remote. Use the -u option to establish the upstream connection as well.
Starter code
# Kaynak dalı uzak depoya gönderSample solution
# Kaynak dalı uzak depoya gönder
git push -u origin feature-searchExpected output
Branch 'feature-search' set up to track remote branch 'feature-search' from 'origin'.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What should be done before opening a PR?
- Push the working branch to the remote repository Correct answer
- Delete the main branch on the remote
- Remove the local .git directory
- Change all commit messages
Explanation: The branch must exist in the remote repository so GitHub can compare it. Therefore, you push it first.
2 Select branches for PR comparison
Base: main
Compare: ____
Base: main
Compare: feature-login
Explanation: The Compare field selects the source branch containing the changes proposed for merging.
3 Steps to open a PR
| Term | Meaning |
|---|---|
git push -u |
Branch and upstream connection |
New pull request |
Start a new PR |
Base |
Select the target branch |
Compare |
Select the source branch |