How to Pull Request (PR)

Recently I came across through Facebook’s Open Source Immersion program.

The goal of this initiative is to provide developers with practical education and experience contributing to Open Source projects in preparation for our annual Developer Circles Community Challenge later this year.

Over one month starting July 15, 2020 at 12:00 AM PST, participants in the Open Source Immersion will be asked to submit a minimum of four Pull Requests (PR), where one out of four of these PRs will need to be aimed towards a Facebook-led Open Source project in the Developer Circles Repo.

read more on facebook developers site…

In order to start contributing to open source projects, it is very important to learn how to work with GIT/GitHub. Trust me best way to learn is to start using it.

Let’s get started – In order to submit the Pull Requests (PR’s) we need to first know what is PR and how to work with it in GitHub.

Barnching, Merging, & Pull requests in GitHub.

Agenda –
  • An overview of branches
  • working with branches on GitHub
  • Pull requests and GitHub flow.
An overview of branching in Git
  • Much more lightweight
  • Branching is very fast
  • Encouraged to be used
  • Works because of the way git works.
    • Snapshots

Note – Commits in Git

Every time you commit git will store a pointer to one of its snapshots.

Note – Branching in git –

  • Branch is a pointer to a commit.
  • Default branch is master
    • points to latest commit.
    • Moves forward with every commit.
    • Use branches for.

When to create branches ?

  1. Features – when creating/adding new features.
  2. Bugs – If you want fix bug.
  3. Experiments – If you want to experiment.

Note –

  • When you create new branches, the Master branch is not changed.
  • Once u are happy with the changes in the branches then merge it with a master.

Demo1 : Creating a Branch on GitHub | The Commands for the Branching.

Create New Branch with this command

$ git branch [ barnch name ]

The above command will show you all the branches in your repo.

$ git checkout [ branch name ]

With the above command you can switch from one branch to another, At this point the files in the working directory are replaced with the one’s in that current branch.

$git push -u [ origin ] [ branch ]

When you create new branch, it is not pushed to GitHub automatically. You will have to use the above command with -u parameter then the new branch will be pushed to Github.

Demo2 : Creating files on Github demo of git branching

In this Demo we will create a local branches and then push those to github.

commands are –

$ git checkout -b "new-branch"

  • The above command will create new branch and will also switch you to that new branch.
  • Next, you make any changes in ur code.
  • Next, stage those changes with the command (git add .)
  • Next, commit those changes with the command (git commit -m "your commit")
  • Then push it to remote branch with the command (git push -u origin [new branch name])

Pull Requests and the GitHub Flow

  • Using the pull request (PR) you are telling that you have pushed to a branch of a repo. and made changes in a separate branch.
  • We need to open the pull request, to discuss review and add more commits.
  • Once this is approved it will be merged into the base branch.

Demo1 : – Working with pull requests.

In this demo we will perform the below given task.

  1. Creating a pull request for our branch
  2. Adding more commits
  3. Adding comments
  4. Exploring the files in the PR (Pull request)
  5. Merging the PR into the branch
  6. Deleting the branch

Step 1: – How to create pull Request on Github ?

Inside your repo where you have created new branch, you will see a Compare and Pull request button.

It will show you the options to Open a pull request
Create a new pull request by comparing changes across two branches. If you need to, you can also .

Step 2: – You can also manually create new pull request by clicking the Pull Request’s tab > New pull Request button.

Note – Able to merge. These branches can be automatically merged.

Note – Now under create pull request button we can also see Create Draft Pull Request (Cannot be merged until marked for review)

Step 3: – Now click Merge Pull request button and click confirm merge.

You will see a message – Pull request successfully merged and closed

And you will get a Delete branch button to delete your baranch.

Note – Inside this button there are 3 options

  • Create a Merge Commit – All commits from this branch will be added to the base branch via a merge commit.
  • Squash and merge – The 1 commit from this branch will be added to the base branch.
  • Rebase and merge – The 1 commit from this branch will be Rebased and added to the base branch.

Step 4: – I clicked on Delete Branch and now I got the message – @trickyj trickyj deleted the add-installation branch now

Note – Once you delete or make changes on GitHub website you will have to fetch/Pull those to your local repo.

% git branch

  • add-installation
  • master

% git fetch
remote: Enumerating objects: 2, done.
remote: Counting objects: 100% (2/2), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (2/2), done.
0df7a36..4bcaa13 master -> origin/master

% git pull
Updating 0df7a36..4bcaa13
installation.txt | 29 +++++++++++++++++++++++++++++
src/Callback.js | 3 ++-
2 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 installation.txt

% git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean