Stacked Pull Requests on Github

At eFuse we write a lot of code which is all peer reviewed by at least one other member of the engineering team. Research has shown that the larger a pull request, the longer it takes to review, the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




GitHub Project Workflow for Multiple Collaborators

Now into phase 4 of my Bootcamp and I have collaborated with a few people on projects. We are given suggestions for things to do when working on projects, but no clear workflow to follow so with each partnership and pairing we create our own system. Fortunately, I have several friends that are engineers and one of them suggested a workflow for collaborating with others when working in the same GitHub repository. I have found this very helpful so I wanted to share this as a template to help navigate the project workflow with more ease.

To start, one of us creates the project and invites the other as a collaborator on Github. We both work from the same repository so there is no need to fork it at this point. You can of course do that later if you have things you want to work on yourself outside of the project, but you need to make sure you and your partner are working from the same one so you both get updates when one of you pushes code.

2. Create a new branch

We want to make sure our main branch stays intact and working. So, rather than working directly in the main branch, you want to create a new branch to make changes. An easy terminal command to do this, and my current preference is git checkout. Git checkout lets you change between git branches. It updates your working directory to what is stored in that branch and allows you to make changes, commit and push them there. That way your changes do not affect the main branch until you have the feature, page, or bug fixed and working smoothly.

I use this command with an additional part to create a new branch to work in.

The -b part is used to create a new branch. I try to be consistent with the way I name the branches I create, so I use my first and last name followed by / . Then I choose a name that is descriptive of what that branch will be used for. Rather than separating my works with spaces, I use a dash, .

When you are in visual studio code, in the bottom left corner you will see what branch you are in.

When I run git checkout -b gracedurant/name-of-new-branch , it automatically takes me to the new branch.

Once I confirm I am in the new branch, I work on the code and make any necessary changes there.

3. Stange and Commit the changes

When I have the feature working as I want it to, I commit those changes. There are different ways to do this. You can do it in the terminal by running the following commands

Although, I prefer to do it in Visual Studio Code by going to the Source Control. The number next to it shows how many new changes you have that still need to be staged and committed.

I find using Visual Studio Code for this easier than the terminal, and it gives me more granularity in my commits. You can group your commits. So if there are multiple changes that are all related, you can keep them together. Or, if there is a change that isn’t related to any others, you can keep it by itself.

By clicking on the + button, you can stage one or more changes for the commit. Enter your commit message in the text field and then hit the Commit button. You go through until there are no more changes, or until you have committed all the desired changes.

Make small commits! Try to work on one thing in your branch. Maybe a simple form. If it is a robust form with several different moving parts, maybe even make each of those parts its own commit. That way if something breaks the code, it is easy to undo without losing other good work you’ve done.

4. Push the change

Then I go back to the terminal and run:

The following message is displayed in the terminal.

I copy and paste the command with the addition of the — set-upstream origin name-of-your-branch and run it.

I can type this all out, but I prefer to copy and paste it to eliminate potential typos.

5. Create the pull request.

When I run the push command with the upstream portion, I get the below message.

Part of that message is a link to create a pull request for the branch I just pushed my changes to. I follow that link by holding the command button while clicking it and it takes me directly to a pull request for my branch on GitHub.

You will see the name of your commit automatically filled in as your Title. You can change that if you like. It is helpful to add a detailed description of what you did in your branch under the Write tab. This will help your partner understand what you actually did in this branch.

You will want to assign your partner as a reviewer under Reviewers.

Then click the Create Pull Request button.

6. Review pull request.

At this point, your partner, who you assigned to review it, will get a notification via email. They can follow the link there, or they can go to the repository and select pull request at the top of the page.

That will take them to the page with all the open pull requests. From there, my partner can select the specific one they want to review.

Here my partner can see the description of what was changed to give them context before they dive into looking at the code. My partner, as the reviewer, navigates to the Files changed tab. It has a number next to it that shows how many files were changed.

Once they have looked over the changes in a particular file, they select the viewed checkbox. It automatically minimizes that file so they can easily move on to the next one to review. They repeat for each changed file.

Once all the files have been reviewed, they select the review changes button.

It then brings up a box where my partner can leave a comment if there are suggested changes for me to make. Then I can review the comments and make any necessary changes. Or if everything looks good, my partner can leave a comment saying something to that effect, select the bubble to approve it, and click the button in the bottom left corner of the box.

7. Merge the branch with the main branch

I will be notified via email once it has been reviewed if there are comments for suggested changes, or if it was approved. I can also navigate directly to the pull request.

If there were suggestions for changes, obviously my partner and I discuss them to make sure we are on the same page. Then I would make the change in my branch and go through the process of staging, committing, and updating the pull request.

If it was approved I can navigate to the pull request and merge it with the main branch. Usually, the partner that authored the code and created the pull request will be the one to merge it, once the other partner has approved it. In this example, I would be the one to merge it with the main branch by clicking the Merge pull request button.

8. Update the main branch on your machine

In Visual Studio Code make sure to go back to your main branch. You can do this by running

And it will switch you back. Confirm this in the bottom left corner. Then run

This will pull down the updated main branch that includes all the recent changes from that merge. You always want to do this before creating a new branch so you start working with the most recent code. It helps reduce merge conflicts that will have to be resolved. This also saves you and your partner time so you are not duplicating work.

9. Repeat.

Here the process repeats itself. I create a new branch and get started on the next feature, page, styling, or bug I decide to tackle. When all the collaborators follow these steps, it helps everyone stay up to date on the code, makes sure everyone is familiar with what is being added and helps prevent large merge conflicts that can be complicated, especially if saved for the end of a project.

Add a comment

Related posts:

State Design Pattern

Summary information about State Design Pattern. “State Design Pattern” is published by Yigit Can Turk.

Selective Pallet Racking

Selective Pallet Racking systems are the most preferred storage system for warehouses with pallet racks manufacturers in Gurgaon. They stock a wide range of fast-moving products. The selective…

The Inflation of the Sex Offender Laws

So you think sex offenders are violent rapists who are a threat to you, your loved ones and especially children. In truth the definition of sex offender is now so broad as to be meaningless. I also…