LoginSignup
0
0

More than 5 years have passed since last update.

How To Create A Pull Request On Github?

Posted at

Beginning

a free and ajar point, Git is a distributed version command system that makes team-based and ajar-point program work more administrable. Many work maintain their records in a git facility, and tracts like GitHub have made coinciding and contributing to code uncomplicated, priceless, and effective.
Open-source work that are socialized in public facilities benefit from tries made by the beamy God gathering through pull questions, which request that a work evaluate changes you have made to its code facility.
This tutorial will govern you through making a pull request to a git facility through the regulate formation so that you can contribute to open-source program projects.

Duties

You should have Git put on your local device. You can draft if Git is put on your computer and go through the beginning process for your directing system by following .

You’ll also need to have or create a github record. You can do so through the GitHub website, , and can either wood in or create your record.

Finally, you should identify an open-source app work to contribute to. You can become more familiar with open-source work by reading through.

Create A Copy Of The Facility

A facility, or repo for short, is essentially the main folder of a project. The facility contains all the relevant project files, including documentation, and also stores the transformation past for each file. On GitHub, repositories can have multiple accessories and can either be public or private.

In order to work on an open-source project, you will first need to make your own copy of the facility. To do this, you should cutlery the facility and then clone it so that you have a local working copy.

Cutlery The Facility

You can easily cutlery a facility on GitHub by navigating with your browser to the GitHub URL of the open-source project you would like to contribute to.

GitHub facility URLs will reference both the username associated with the owner of the facility, as well as the facility name. For example, FxDataCloud is the owner of the project facility, so the GitHub URL for that project is:

https://github.com/FxDataCloud/netbox

In the above instance, FxDataCloud is the username and netbox is the facility name.

Once you have determined the work you would like to contribute to, you can navigate to the address, which will be formatted like so:

https://github.com/username/facility 

Or you can search for the work using the GitHub search bar.

When you’re on the main page for the facility, you’ll see a “cutlery” button on your top right-hand side of the page, underneath your user icon:
image.png

sound on the cutlery fastener to begin the elevating process. Within your spectator window, you’ll collect feedback that looks like this:

Once the process is done, your browser will go to a screen similar to the facility image above, except that at the top you will see your username before the facility name, and in the URL it will also say your username before the facility name.

So, in the instance above, instead of FxDataCloud / netbox at the top of the leaf, you’ll see your-username / netbox, and the brand-new URL will look like this:

https://github.com/your-username/netbox

With the facility divided, you’re ready to clone it so that you have a local working copy of the code base.

Clone The Facility
To make your own local copy of the facility you would like to contribute to, let’s first open up a terminal window.

We’ll use the git clone control along with the URL that points to your cutlery of the facility.

This address will be akin to the address above, except now it will extremity with .git. In the NetBox instance above, the address will look like this:

https://github.com/your-username/netbox.git

You can alternatively copy the URL by using the green “Clone or download” button from your facility page that you just divided from the original facility page. Once you click the button, you’ll be able to copy the URL by clicking the harvester button next to the URL:
image.png
Once we have the URL, we’re ready to clone the facility. To do this, we’ll have the git clone command with the facility URL:

git clone https://github.com/your-username/facility.git

Now that we have a local copy of the code, we can move on to creating a brand-new branch on which to work with the code.

Create A Brand-New Branch

Whenever you work on a cooperative project, you and other engineers contributing to the facility will have different concepts for new features or difficulties at once. Some of these new features will not take momentous time to implement, but some of them will be current. Because of this, it is important to branch the facility so that you are able to manage the advancement, discriminate your code, and control what features make it back to the main branch of the project facility.

The default main branch of a project facility is usually called the boss branch. a common best practice is to consider anything on the boss branch as being deployable for others to use at any time.

When creating a branch, it is very important that you create your new branch off of the boss branch. You should also make sure that your branch name is a descriptive one. Rather than labelling it my-branch, you should go with frontend-hook-migration or fix-documentation-typos instead.

To create our branch, from our terminal window, let’s change our directory so that we are working in the directory of the facility:

 cd facility 

Now, we’ll create our brand-new branch with the git branch control. Make convinced you name it descriptively so that others working on the work understand what you are working on.

git branch new-branch

Now that our brand-new branch is created, we can switch to make convinced that we are working on that branch by using the git examination control:

git examination new-branch

Once you enter the git examination control, you will collect the following output:

Output
Switched to branch 'new-branch' 

Alternatively, you can liquefy the above two controls, creating and switching to a brand-new branch, with the following command and -b emblem:

 git examination -b new-branch

If you want to switch back to boss, you’ll use the examination command with the name of the boss branch:

git examination boss 

The examination control will allow you to switch between aggregate divisions, so you can potentially work on aggregate features at once.

At this component, you can now alter existing records or increase brand-new records to the work on your own branch.

Make Changes Locally
Once you have modified existing files or added new files to the project, you can add them to your local facility, which we can do with the git increase control. Let’s increase the -A emblem to increase all changes that we have made:

git increase -A 

Next, we’ll want to record the changes that we made to the facility with the git commit command.

The commit communication is an important feature of your code attempt; it helps the other donors fully understand the change you have made, why you made it, and how momentous it is. Additionally, commit communications provide a historical record of the changes for the project at large, aiding future donors along the way.

If we have a very short communication, we can record that with the -m emblem and the communication in interruptions:

git commit -m "Fixed documentation typos"

But, unless it is a very insignificant change, we will more than likely want to include a lengthier commit communication so that our accessories are fully up to speed with our contribution. To record this larger message, we will run the git commit regulate which will ajar the absence text editor:

git commit 

If you would like to configure your absence text editor, you can do so with the git config control, and set nano as the absence editor, for instance:

git config --global core.editor "nano"

Or vim:

git config --global core.editor "vim" 

After running the git commit control, being on the absence text editor you’re using, your terminal window should display a paper-work prepared for you to edit that will look akin to this:
antelope nano 2.0.6 File: …username/facility/.git/COMMIT_EDITMSG

# Please enter the commit communication for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch new-branch # Your branch is up-to-date with 'origin/new-branch'. # # Changes to be committed: # modified: new-feature.py # 

Underneath the opening comments, you should add the commit communication to the text file.
To write an useful commit communication, you should include a statement on the first line that is around 50 characters long. Under this, and ended up into assimilable sections, you should include a description that states the reason you made this change, how the code works, and additional information that will make it easier for others to review the work when integrating it. Try to be as helpful and proactive as possible to ensure that those maintaining the project are able to fully understand your contribution.
Once you have saved and exited the commit communication text file, you can verify what git will be acting with the following control:

 git status 

being on the changes that you have made, you will collect output that looks something like this:

Output
On branch new-branch Your branch is ahead of 'origin/new-branch' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working directory clean 

At this component you can use the git push command to push the changes to the current branch of your divided facility:

git push --set-upstream origin new-branch 

The control will give you with product to let you know of the improvements, and it will look akin to the following:

Output 
Counting objects: 3, done. Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 
336 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) 
To https://github.com/your-username /respository .git 
a1f29a6..79c0e80 new-branch -> new-branch Branch new-branch set up 
to track remote branch new-branch from origin. 

You can now navigate to the divided facility on your GitHub webpage and instruction to the branch you just moved to see the changes you have made in-browser.

At this component, it is feasible to make a pull request to the original facility, but if you have not already done so, you’ll want to make sure that your local facility is up-to-date with the upstream facility.

Modify Local Facility
While you are working on a project alongside other donors, it is important for you to keep your local facility up-to-date with the project as you don’t want to make a pull request for code that will cause conflicts. To keep your local copy of the code base updated, you’ll need to sync changes.

We’ll first go over assembling a far for the cutlery, then altering the cutlery.

Configure A Far For The Cutlery
far facilities make it possible for you to work with others on a git project. Each remote facility is a version of the project that is entertained on the Internet or a network you have access to. Each remote facility should be accessible to you as either read-only or read-write, depending on your user privileges.

In order to be able to sync changes you make in a cutlery with the original facility you’re working with, you need to configure a remote that remarks the upstream facility. You should set up the remote to the upstream facility only once.

Let’s first draft which far servers you have configured. The git far command will list whatever remote facility you have already specified, so if you copied your facility as we did above, you’ll at least see the point facility, which is the default name given by Git for the copied directory.

From the directory of the facility in our terminal window, let’s use the git far control along with the -v emblem to display the addresses that Git has kept along with the applicable far shortnames (as in “component”):

git far -v 

Since we copied a facility, our output should look similar to this:

Output
origin https://github.com/your-username/forked-facility.git (fetch) 
origin https://github.com/your-username/forked-facility.git (push) 

If you have previously set up more than one far, the git far -v regulate will give a database of all of them.

Next, we’ll specify a new remote upstream facility for us to sync with the cutlery. This will be the original facility that we divided from. We’ll do this with the git far add command.

git far add upstream https://github.com/original-owner-username/original-facility.git 

In this instance, upstream is the shortname we have given for the remote facility since in terms of Git, “upstream” refers to the facility that we copied from. If we want to add a remote mark to the facility of an accessory, we may want to provide that accessory’s username or a reduced appellation for the shortname.

We can verify that our remote mark to the upstream facility was properly added by using the git far -v command again from the facility directory:

 git far -v

 Output
origin https://github.com/your-username/forked-facility.git (fetch) 
origin https://github.com/your-username/forked-facility.git (push) 
upstream https://github.com/original-owner-username/original-
facility.git (fetch) upstream https://github.com/original-owner-
username/original-facility.git (push) 

Now you can refer to upstream on the command line instead of writing the entire URL, and you are ready to sync your cutlery with the original facility.

Sync The Cutlery
Once we have configured a remote that remarks the upstream and original facility on GitHub, we are ready to sync our cutlery of the facility to keep it up-to-date.

To sync our cutlery, from the directory of our local facility in a terminal window, we’ll use the git transfer command to transmit the divisions along with their individual commits from the upstream facility. Since we used the shortname “upstream” to refer to the upstream facility, we’ll pass that to the control:

git transfer upstream 

Depending on how many changes have been made since we divided the facility, your output may be different, and may include a few lines on determining , wedging , and removing objects. Your output will end similarly to the following lines, but may vary depending on how many divisions are part of the project:

Output
From https://github.com/original-owner-username/original-facility * [new branch] boss -> upstream/boss

Now, commits to the boss branch will be stored in a local branch called upstream/boss.

Let’s switch to the local boss branch of our facility:

git examination boss 

Output
Switched to branch 'boss'

We’ll now integrate any changes that were made in the original facility’s boss branch, that we will access through our local upstream/boss branch, with our local boss branch:

git merge upstream/boss

The product here will vary, but it will commence with Updating if changes have been made, or Already up-to-date. if no changes have been made since you divided the facility.

Your fork's boss branch is now in sync with the upstream facility, and any local changes you made were not lost.

Depending on your own advancement and the amount of time you disburse on making changes, you can sync your cutlery with the upstream code of the original facility as many times as it makes awareness for you. But you should certainly sync your cutlery right before making a pull request to make sure you don’t contribute contrasting code.

Create Pull Request
At this point, you are ready to make a pull request to the original facility.
You should navigate to your divided facility, and press the “New pull request” button on your left-hand side of the page.
image.png
You can modify the branch on the next screen. On either site you can select the appropriate facility from the drop-down menu and the appropriate branch.

Once you have specified , for example, the boss branch of the original facility on the left-hand side, and the new-branch of your divided facility of the right-hand side, you should see a screen that looks like this:
image.png
GitHub will alert you that you are able to compound the two divisions because there is no challenging code. You should increase in a heading, a comment, and then press the “Create pull request” button.

At this point, the supporters of the original facility will decide whether or not to accept your pull request. They may ask for you to edit or rewrite your code prior to evaluating the pull request.

Judgment
At this point, you have successfully sent a pull request to an open-source software facility. Following this, you should make sure to update and rebase your code while you are waiting to have it analyzed . Project supporters may ask for you to rework your code, so you should be prepared to do so.

Contributing to open-source work — and becoming a progressive open-source God — can be a bountied education. Making constant tries to program you frequently use allows you to make convinced that that program is as valuable to other extremity people as it can be.

Reference
https://fxdata.cloud/tutorials/create-a-pull-request-on-github
https://fxdata.cloud

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0