{"id":1645,"date":"2012-11-10T16:33:07","date_gmt":"2012-11-10T21:33:07","guid":{"rendered":"http:\/\/www.rexfeng.com\/blog\/?p=1645"},"modified":"2012-11-10T16:33:07","modified_gmt":"2012-11-10T21:33:07","slug":"how-to-close-a-git-pull-request","status":"publish","type":"post","link":"https:\/\/www.rexfeng.com\/blog\/2012\/11\/how-to-close-a-git-pull-request\/","title":{"rendered":"How to Close a Git Pull Request"},"content":{"rendered":"<p>With a git workflow, you become used to commands like [cci]git add filename[\/cci] and [cci]git commit -m &#8220;add filename&#8221;[\/cci]. When you maintain an open source project and get a pull request, the exact workflow may get murky. How do you review the pull request work? How do you accept the commit if it passes muster?<\/p>\n<p>This post will cover how to review, accept, and close a <a href=\"https:\/\/github.com\/\">GitHub<\/a> pull request.<\/p>\n<p>In our example, we are the creator of a popular open source project called <a href=\"https:\/\/github.com\/xtatest\/breakfast-sandwich\">breakfast-sandwich<\/a>. In our rush to get the product out, we forgot a critical piece &#8211; the breakfast sandwich has no cheese! Luckily, our project is open source and we&#8217;ve already received a pull request to add cheese to our sandwich.<\/p>\n<p>Here&#8217;s the ingredients [cci]list.txt[\/cci] file initial state, missing cheese:<\/p>\n<p style=\"padding-left: 30px;\">[cc]# ingredients list<br \/>\n* english muffin<br \/>\n* eggs<br \/>\n* sausage\u00a0[\/cc]<\/p>\n<p>Here&#8217;s the pull request on GitHub:<\/p>\n<div id=\"attachment_1665\" style=\"width: 550px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1665\" class=\"size-large wp-image-1665\" title=\"1-pull-request\" src=\"http:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-request-540x296.png\" alt=\"Pull Request\" width=\"540\" height=\"296\" srcset=\"https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-request-540x296.png 540w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-request-150x82.png 150w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-request-300x164.png 300w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-request-624x342.png 624w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-request.png 945w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><p id=\"caption-attachment-1665\" class=\"wp-caption-text\">A pull request received<\/p><\/div>\n<div id=\"attachment_1668\" style=\"width: 550px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1668\" class=\"size-large wp-image-1668\" title=\"1-pull-req-detail\" src=\"http:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-req-detail-540x366.png\" alt=\"The Pull Request detail\" width=\"540\" height=\"366\" srcset=\"https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-req-detail-540x366.png 540w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-req-detail-150x101.png 150w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-req-detail-300x203.png 300w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-req-detail-624x423.png 624w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/1-pull-req-detail.png 959w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><p id=\"caption-attachment-1668\" class=\"wp-caption-text\">The Pull Request detail<\/p><\/div>\n<h3>1. Add the fork&#8217;s pull request repo as a remote<\/h3>\n<p style=\"padding-left: 30px;\">[cc]$ git remote add xta https:\/\/github.com\/xta\/breakfast-sandwich.git[\/cc]<\/p>\n<p style=\"padding-left: 30px;\">You can verify that the remote [cci]xta[\/cci] has been added by running the [cci]git remote[\/cci] command.<\/p>\n<h3>2. Fetch the git data from remote<\/h3>\n<p style=\"padding-left: 30px;\">[cc]$ git fetch xta<br \/>\nremote: Counting objects: 5, done.<br \/>\nremote: Compressing objects: 100% (3\/3), done.<br \/>\nremote: Total 3 (delta 0), reused 3 (delta 0)<br \/>\nUnpacking objects: 100% (3\/3), done.<br \/>\nFrom https:\/\/github.com\/xta\/breakfast-sandwich<br \/>\n* [new branch] add-cheese-to-list -&gt; xta\/add-cheese-to-list<br \/>\n* [new branch] master -&gt; xta\/master[\/cc]<\/p>\n<h3>3. Checkout the remote branch<\/h3>\n<p style=\"padding-left: 30px;\">[cc]$ git co xta\/master<br \/>\nNote: checking out &#8216;xta\/master&#8217;.<br \/>\nYou are in &#8216;detached HEAD&#8217; state. You can look around, make experimental<br \/>\nchanges and commit them, and you can discard any commits you make in this<br \/>\nstate without impacting any branches by performing another checkout.<br \/>\nIf you want to create a new branch to retain commits you create, you may<br \/>\ndo so (now or later) by using -b with the checkout command again. Example:<br \/>\ngit checkout -b new_branch_name<br \/>\nHEAD is now at be7c26d&#8230; add cheese to ingredients list[\/cc]<\/p>\n<h3>4. Checkout to a new test branch<\/h3>\n<p style=\"padding-left: 30px;\">[cc]$ git co -b &#8220;test-add-ingredient&#8221;<br \/>\nSwitched to a new branch &#8216;test-add-ingredient'[\/cc]<\/p>\n<h3>5. Test the current branch<\/h3>\n<p style=\"padding-left: 30px;\">For this step, you would need to perform whatever steps your project deems appropriate before accepting a pull request.<\/p>\n<p style=\"padding-left: 30px;\">We can open up [cci]list.txt[\/cci] and see that it now contains cheese:<\/p>\n<p style=\"padding-left: 30px;\">[cc]# ingredients list<br \/>\n* english muffin<br \/>\n* eggs<br \/>\n* sausage<br \/>\n* cheese[\/cc]<\/p>\n<p style=\"padding-left: 30px;\">As the updated ingredients from [cci]xta\/master[\/cci] pass our critiera, we need to merge it back into master branch.<\/p>\n<h3>6. Check your feature branch against master to make sure any merge conflicts happen in your feature branch<\/h3>\n<p style=\"padding-left: 30px;\">[cc]$ git rebase master<br \/>\nCurrent branch test-add-ingredient is up to date.[\/cc]<\/p>\n<h3>7. Merge feature branch into master<\/h3>\n<p style=\"padding-left: 30px;\">First, switch to master branch:<\/p>\n<p style=\"padding-left: 30px;\">[cc]$ git co master<br \/>\nSwitched to branch &#8216;master'[\/cc]<\/p>\n<p style=\"padding-left: 30px;\">Then merge the feature branch into master.<\/p>\n<p style=\"padding-left: 30px;\">[cc]$ git merge test-add-ingredient<br \/>\nUpdating 5004985..be7c26d<br \/>\nFast-forward<br \/>\nlist.txt | 3 ++-<br \/>\n1 file changed, 2 insertions(+), 1 deletion(-)[\/cc]<\/p>\n<h3>8. Push your master onto GitHub<\/h3>\n<p style=\"padding-left: 30px;\">Great job! We&#8217;ve reviewed the feature branch, merged it into master locally. So now, we need to make sure the internet has access to our open source breakfast sandwich that includes cheese.<\/p>\n<p style=\"padding-left: 30px;\">[cc]$ git push<br \/>\nCounting objects: 5, done.<br \/>\nDelta compression using up to 4 threads.<br \/>\nCompressing objects: 100% (3\/3), done.<br \/>\nWriting objects: 100% (3\/3), 343 bytes, done.<br \/>\nTotal 3 (delta 0), reused 0 (delta 0)<br \/>\nTo git@github-xtatest:xtatest\/breakfast-sandwich.git<br \/>\n5004985..be7c26d master -&gt; master[\/cc]<\/p>\n<p style=\"padding-left: 30px;\">When you look at your GitHub repo, you&#8217;ll see that the pull request is now closed. Most importantly, our breakfast sandwich has cheese!<\/p>\n<div id=\"attachment_1670\" style=\"width: 550px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1670\" class=\"size-large wp-image-1670\" title=\"2-closed-request\" src=\"http:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/2-closed-request-540x294.png\" alt=\"Closed Pull Request\" width=\"540\" height=\"294\" srcset=\"https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/2-closed-request-540x294.png 540w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/2-closed-request-150x81.png 150w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/2-closed-request-300x163.png 300w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/2-closed-request-624x340.png 624w, https:\/\/www.rexfeng.com\/blog\/wp-content\/uploads\/2012\/11\/2-closed-request.png 947w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><p id=\"caption-attachment-1670\" class=\"wp-caption-text\">Closed Pull Request<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>With a git workflow, you become used to commands like [cci]git add filename[\/cci] and [cci]git commit -m &#8220;add filename&#8221;[\/cci]. When you maintain an open source project and get a pull request, the exact workflow may get murky. How do you review the pull request work? How do you accept the commit if it passes muster? [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1029],"tags":[1035,1033,338,1030,1034,1031,1032],"class_list":["post-1645","post","type-post","status-publish","format-standard","hentry","category-programming","tag-branch","tag-close","tag-git","tag-github","tag-issue","tag-pull","tag-request"],"_links":{"self":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts\/1645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/comments?post=1645"}],"version-history":[{"count":16,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts\/1645\/revisions"}],"predecessor-version":[{"id":1680,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts\/1645\/revisions\/1680"}],"wp:attachment":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/media?parent=1645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/categories?post=1645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/tags?post=1645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}