Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 23, 2020 06:18 pm GMT

Introduction to Branches and Pull Requests for Beginners.

Branches and pull requests are essential to the GitHub workflow, they help developers work together in a better and organised way. If you've never heard of them that's okay. My goal in this tutorial is to help you understand what they are and how they are used when working on repositories.

What are Branches?

A branch simply put is an isolated environment that is created from the master branch that allows you to experiment on new ideas or makes bug fixes without affecting the master branch or being affected by the changes committed by others to the same repository.

You can use branches to safely develop and test new features. When the features are ready to be deployed, a pull request is opened to review the changes you made.

What are pull requests?

A pull request is a feature that allows you to inform others of the changes you've made to the repository through your branch. It allows you to share screenshots and general ideas or seek help and advice when you're stuck.

The repository owner reviews the work you've done on your branch and they can get back to you either for more info about the changes you made or point out a bug you may have missed. Once the pull request has been reviewed and has passed all the tests. The branch can then be merged with the master branch.

Creating a branch

In order to create a branch. Make sure you are signed in into your GitHub account. Navigate to the repository you wish to create a branch in and click on the master button.

To create a new branch, type the name of your new branch in the space provided. For this tutorial I'll call mine readme-edits since I'll be editing the README document.

Alt Text

Hit enter and your repository will switch to the new branch. The button that was written master has now changed to readme-edits this shows us which branch we are currently working on. To switch back to master; click on the readme-edits button then select master.

Alt Text

The black checkmark is also another way to know which branch you are currently working on.

Making Changes

Open the README file from the readme-edits branch and make some changes.

After editing your document, add a commit message, you can also add an optional description, then click on commit changes

Alt Text

Opening a Pull Request

After your changes have been committed, we can now open a pull request, so that the repository owner (in this case it's you) can review your work and merge it with the master branch.

In the top pane click on the pull request tab.
Alt Text

Immediately after opening you will receive a prompt to Compare & pull request since GitHub has noticed new changes that are not in the master branch. click on the Compare & pull request button.

Alt Text

After clicking the button you will see this window below, here you can add a more in-depth explanation of the changes you made, you can also add media such as images and emojis using markdown. This will be visible to those reviewing your pull request. Finally click on create pull request.

Alt Text

Once you've created your pull requests, you are free to make changes to files within the repository in the same branch and all your commits will be added to your pull request, the changes will be visible within the "Files changed" tab.

Alt Text

Merging a pull request

Once your changes have been verified, now it's time to merge them into your master branch. Pull Requests just like commits are searchable, they let you go back in time to understand why some changes were made and how it happened.

Click Merge pull request then click confirm. Seeing the box down below confirms that it has been merged. You can choose to delete the branch as well if you won't be needing it anymore.
Alt Text

If you switch back to the master branch you will see the updated changes.

Here is a diagram that summarises the steps undertaken when opening a pull request.

Alt Text

And these are the basics you need to know when creating branches and opening pull requests. If you need more explanations on this feel free to reach out. If you have a topic you would like to see covered in a future post, feel free to tell me in the comments.

Thank You for Reading .


Original Link: https://dev.to/inezabonte/introduction-to-branches-and-pull-requests-for-beginners-3kjc

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To