[ad_1]
Welcome back to GitHub for beginnersa series to help you navigate GitHub.
So far in this series we have covered the most important Git commands every developer should know, How to create repositories, How to upload files and folders to your repositoryAnd How to add code to your repository. In our last post, we talked briefly about pull requests, but now we’ll dive into them in depth. In this post, you’ll learn how to create a pull request so you can propose changes to a repository and have those changes reviewed by others before you commit them.
Let’s get started!
What is a pull request?
A pull request (often called a “PR”) is a proposal to merge a set of changes from one branch into another. Creating a pull request allows you to review a set of changes with others before they are merged into the main code base. Before we get to that, it’s helpful to define some terms.
- Source branch: the branch that contains your changes.
- Target industry: the branch into which you want to merge your changes.
Pull requests provide a visual representation of the content differences between the source and target branches, allowing you to review the changes before accepting them and pulling them to the target branch.
Creating your pull request
You can create a pull request on GitHub.com with GitHub Desktop, GitHub CodespacesTo GitHub Mobileand when using the GitHub Command Line InterfaceYou can also create a pull request from the terminal with git
and that is what we will do here.
On GitHub, navigate to your repository, clone it, and create a new branch. If you need a refresher course on any of these steps, see the previous GitHub for beginners entries. For the purposes of this guide, we have created a new branch in our repository called Update Name. After creating this branch, open your terminal and run git checkout -b update-name
to Update Name Branch.
Open a file in the repository in your editor and make a change. In our case, we made a change to the Home File. Don’t forget to save the file!
Complete the steps to deploy and commit your changes by running the following commands in the terminal:
git add .
git commit -m "update game name"
Once these commands are completed, run git status
to make sure the changes were successfully committed. If so, you should see a message indicating that there is nothing to commit and your work tree is clean. Awesome!
Now you need to push your changes to the repository on GitHub. You do this by git push origin update-name
in the terminal. Remember that if you used a different name for your branch, you must replace update-name
with the name of your branch: git push origin your-branch-name
.
Navigate to GitHub. You should see a message indicating that your branch has recently received pushes. Click the green “Compare and Pull Request” button. This will take you to the pull request page where you can enter the information for your pull request.
At the top left of the page there is a dropdown button that says “base:” followed by a branch name. Most likely this is “base: primarily.” This specifies the branch you want to merge the changes into, also known as the target branch. Click the button and select “main” if it is not already selected.
The dropdown box directly to the right of the “Base:” field is the “Compare:” field. This shows the branch you are merging from, also known as the source branch. Click this field and select the branch where you made your changes.
After making sure the target and source branches are set correctly, add a title and description for the pull request. The description should explain the changes you made. If you’re not ready to have your changes reviewed yet, you can create a draft pull request. Or you can create a pull request for review by clicking the green “Create pull request” button. Do that now.
Congratulations! You’ve created your pull request! Now you can have your changes reviewed by someone else on the team. Once reviewed, you can merge your changes into the target branch by clicking the green “Insert Pull Request” button at the bottom of the page.
Things you should consider
There are some best practices you should keep in mind when creating pull requests in the future.
- Write small pull requests. Smaller pull requests are easier and faster to review and merge, offer less room for errors, and provide a clearer change history.
- Review your own pull request first. Review, create, and test your own pull request before submitting it. This will help you catch any errors or typos you may have missed before others start reviewing.
- Provide context and guidance. Write clear titles and descriptions for your pull requests so that reviewers can quickly understand what the pull request does. You should include the following in the body of your pull request:
- The purpose of the pull request
- An overview of the changes
- Links to additional context such as tracking issues, tickets or previous conversations
Your next steps
Now that you can create pull requests, you can this repository to practice building. Once you feel comfortable creating pull requests, you can propose changes to existing repositories and offer your own contributions for review. It’s a great way to collaborate, so give it a try!
If you have any questions, please ask them in the GitHub Community Thread and we will surely answer.
Here are some more resources to help you on your journey with GitHub:
Written by
[ad_2]
Source link