Git Pull Request Workflow

Learn to code, learn web development basics, start a career in tech.

Git Pull Request Workflow

Last edited: Jul 10 2019

Git Pull Request Workflow

After you have made changes to a repository, maybe you added a new feature to the code or fixed a bug, you will then submit your work so other collaborators on the project can approve the change before merging that change into the main branch, which is typically the master branch.

The process of making changes and submitting these changes for approval is called creating a "pull request"

I will now walk you through step by step scenario of how to create a pull request to be merged into the master branch.

Master Branch

In this example, in the end, we want to merge back into master, so it is important to make sure that we are starting our work from the master branch, so the first step is to make sure you are in the master branch.

 git branch 

In the code above we check if we are currently on the master branch, you will notice (*) symbol next to master branch if you are already checkout out into master.

Git Checkout Master

If you are not on the master branch then you need to follow the instruction below to checkout master.

 git checkout master 

Git Pull

Now on the master branch, we want to make sure we have the latest code, this is to make sure that the work in the remote server is the same as the work on our local git repository.

You can skip this step if you have never pushed your code up to github

 git pull origin master 

Now our work is up to date, and we are now ready to create our feature branch.

Feature Branch

Feature branch is a branch we create from master to focus on adding a new feature to our code.

 git checkout -b adding-about-page 

In the example above we are checking out into a new branch called "adding-about-page", the (-b) flag stands for "branch" the branch name is a brief summary of what we are about to do, this ideally should not be a sentence, just a short topic will be enough.

 git branch 

Checking git branch you will notice that we are now checked out into our newly created branch. Now you can make your changes, introduce a new about us page or whatever changes you want.

Commit Your Changes

Whilst still on the feature branch you created, after making the changes, it is time to commit the change.

 # have a quick glance of your changed files
git status

# stage all your changes
git add .

# create a snap shot of your changes
git commit -m'added about us page'

Excellent! you have committed your changes, it is now time to push up your new branch to github.

Git Push Feature Branch

What we now want to do is push up your newly created branch, in my case it is a branch called "adding-about-page"

 git push origin adding-about-page 

The above code will push up our new branch, and now on github we have a new branch called "adding-about-page" or whatever you have called your own branch. Now it is time to create a pull request.

Create Pull Request

Back on github, click on the branch select option as shown in the image below, select your newly created feature branch, and then click "new pull request" button next to it.

You have now successfully created a pull request, your reviewer/reviewers can now go over your changes and if all goes well, your work will be approved and then merged into master branch.

The merge work is all done on github, after that you can delete the feature branch from github.

Update Local Master

Once your work has been merged into master branch in github, you need to update your local copy of master, so first thing to do is, checkout master and pull into it.

 # change into the master branch
git checkout master

# pull new updates from master
 git pull origin master 

Now we have checked out master branch and brought our local copy up to date.

Delete Feature Branch

Since the feature branch "adding-about-page" has already been merged into master, we no longer need to have that local copy of it on our computer, so let's delete it.

 # list all local branches
git branch

# delete a branch
 git branch -d adding-about-page 

That is it! we have successfully created a pull request, and when our work was merged into master branch we cleaned up our git repository by deleting the feature-branch.

I hope you have found this useful! go on now and repeat this steps a few more times until it feels natural, and happy coding!!!