Giter Site home page Giter Site logo

github-pull-request-basics-v-000's Introduction

GitHub Pull Request Basics

Problem Statement

The concept of a pull request is unique to GitHub — so don't feel nervous about not knowing what it is! "Pull requests" power the communities of developers who create and contribute to "open sourced" projects on GitHub.

Through this process, anyone can

  1. fork a repo from its original organization
  2. clone it to a local machine
  3. Make changes in a feature branch on their local system
  4. push their branch to their forked repo

...and now the critical step....

  1. Suggest that the original organization pull the changes that make up the feature branch back to the original repository.

Instead of the owner working on their codebase alone, anyone can contribute tests, documentation fixes, new features, layout, graphics, etc. It's an awesome feeling when you wake up and see that someone you've never met has made an improvement to your code that they'd like to contribute! How does this feature work?

Objectives

  1. Explain what a pull request is
  2. Identify how to create a pull request from a fork to a repo
  3. Identify how to add commits to an existing pull request

Explain What a Pull Request Is

A pull request is a request to the owner of another repo to take changes you made in a branch on your fork of their repo and integrate it into theirs as if you had done the work on theirs directly. It is a request for the owner of a repository to accept your changes, that you made on your own copy of the repo ("your fork"), and "pull" them into the owner's repository. Here is a great example of a pull request on the Ruby codebase.

CAREFUL git has a command called pull which means "integrate changes made in a remote place to this current branch." Oddly, in a "pull request" this isn't really what's happening. You're asking someone to git merge your branch into theirs — a completely different command. It's needlessly confusing. We'll cover merge later, but don't get confused by git pull and "pull request."

Identify How to Create a Pull Request from a Fork to a Repo

Let's go over a conceptual, hypothetical example. It's okay if this feels a bit confusing at first. You'll work through this countless times and eventually your brain and fingers will both grasp what's going on. Let's look at the following example:

  1. Let's pretend that the learn-co-students organization has a repo called awesome-lab, and we make a "fork" from this repo at https://github.com/learn-co-students/awesome-lab.
  2. You would now have a copy of that repo on your GitHub account ("organization") i.e. https://github.com/your-user-name/awesome-lab. Technologists would say you "forked" the awesome-lab repo from the learn-co-students organization to the your-user-name organization.
  3. However, you still would not have a local copy of this repository on your computer.
  4. You would clone from your fork to your computer. There's no reason you couldn't clone from the original repo. However, most repo owners don't want random people on the internet (like you!) committing to their repo. What you're going to do is establish a "parallel" repo in your org and then tell the "source" repo "Hey, I added something awesome, I'm requesting that you pull it in."
  5. Make some changes on your local machine in a branch
  6. Push your code branch from your local system back to your fork
  7. Create a pull request that requests your improved code be "pulled" into the source repo. Observe the steps for initiating a pull request below:

Step 1

Be sure to click New pull request on your fork instead of on the source repo. Otherwise, GitHub won't see the changes that you want to make.

Step 2

Here you can choose the base fork, which will be their-user-name/awesome-lab. Then choose the head fork, which will be your-user-name/awesome-lab

Now click Create pull request, and you're all set!

What if another student now forks the repository https://github.com/learn-co-students/awesome-lab as https://github.com/their-user-name/awesome-lab, then you make some changes and you want to send a pull request to their fork https://github.com/their-user-name/awesome-lab? How do you do this?

Luckily, git doesn't care whether one repository is the "source" or is "another fork of the source." If GitHub magically vanished tomorrow, local copies on hundreds of laptops 'round the world are just as good as the copy that GitHub had! This is why git is called a "Distributed Version Control System." So, to share a pull request with another student follows the same process as forking some famous project (like Ruby or jQuery).

Identify How to Add Commits to an Existing Pull Request

Let's say you make a pull request from https://github.com/your-user-name/awesome-lab to https://github.com/learn-co-students/awesome-lab. Then you notice you made a typo in your code. All you have to do is fix the typo, commit it and push up the changes to your branch. As long as the pull request already exists, the commits will be added automatically.

Conclusion

Pull requests are merely a tool that allows project owners and project editors to collaborate without granting too much direct access, or potentially stepping on each others' toes. This action can be performed even on a repo you are a collaborator on, but may not have write access to — but we won't get into that just yet. You'll continue to learn more about collaboration and how git enables you to track and edit projects to your heart's content!

View GitHub Pull Request Basics on Learn.co and start learning to code for free.

github-pull-request-basics-v-000's People

Contributors

sgharms avatar drakeltheryuujin avatar sdcrouse avatar maxwellbenton avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.