CodeBlanks Logo Icon CodeBlanks

Opening a PR

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-login

After 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 feature

The 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

terminal
# Kaynak dalı uzak depoya gönder

Sample solution

terminal
# Kaynak dalı uzak depoya gönder
git push -u origin feature-search

Expected 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

Question
Base: main
Compare: ____
Answer
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

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow