{"componentChunkName":"component---src-templates-post-jsx","path":"/blog/007-completing-prs-locally-from-bitbucket/","result":{"data":{"markdownRemark":{"html":"<p>For this example, we’ll use the repository ‘cuttle-repo’ from Cuttlesoft that has been forked by user emilyemorehouse.</p>\n<p>The repository URL of the base repository is therefore <code class=\"language-text\">https://bitbucket.org/cuttlesoft/cuttle-repo</code> and the forked repository is <code class=\"language-text\">https://bitbucket.org/emilyemorehouse/cuttle-repo</code>.</p>\n<p>We should first realize that pull requests are essentially requests to merge an ENTIRE branch in (one of the reasons why branching standards are incredibly important while using source control). If commits are made on a branch which already has a PR open, the new commits are also included in the existing PR. Also, if a PR is accepted, a new PR on that same branch will pull in ALL commits from that branch, not just the existing ones.</p>\n<p>Let’s begin.</p>\n<h2 id=\"standard-fetchtestmerge\"><a href=\"#standard-fetchtestmerge\" aria-label=\"standard fetchtestmerge permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>STANDARD FETCH/TEST/MERGE:</h2>\n<h3 id=\"acquire-new-changes\"><a href=\"#acquire-new-changes\" aria-label=\"acquire new changes permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>ACQUIRE NEW CHANGES:</h3>\n<ol>\n<li>First, ensure that you don’t have any outstanding changes:\n<code class=\"language-text\">$ git status</code></li>\n<li>Next, fetch the changes from the desired branch. Typically, this will be from a feature branch, as we encourage users to utilize our standard branching structure. You can use the HTTPS url or SSH.\nUsing SSH:\n<code class=\"language-text\">$ git fetch git@bitbucket.org:emilyemorehouse/cuttle-repo.git feature/new-thing</code>\nUsing HTTPS:\n<code class=\"language-text\">$ git fetch https://bitbucket.org/emilyemorehouse/cuttle-repo feature/new-thing</code></li>\n</ol>\n<h3 id=\"view-and-test-fetched-changes\"><a href=\"#view-and-test-fetched-changes\" aria-label=\"view and test fetched changes permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>VIEW AND TEST FETCHED CHANGES:</h3>\n<ol start=\"3\">\n<li>To view the changes that you wish to merge, run the following command:\n<code class=\"language-text\">$ git diff master FETCH_HEAD</code>\nHere, master is our local branch we want to check against (it may be common to merge into a feature branch of the base repository if multiple users are working on a single feature, and the feature is not yet completed but is ready to be merged up). FETCH_HEAD will contain all changes that have been fetched from the forked repository, though they are not yet available to us to actually run (i.e. <code class=\"language-text\">$ git status</code> will not display these changes yet).</li>\n<li>To run the code as is (prior to merging), run:\n<code class=\"language-text\">$ git checkout FETCH_HEAD</code>.\nThis will create a detached HEAD state, which will allow you to test the new changes. <code class=\"language-text\">$ git log</code> will now contain the fetched commits.</li>\n</ol>\n<h3 id=\"merge-up-the-pull-request--branch\"><a href=\"#merge-up-the-pull-request--branch\" aria-label=\"merge up the pull request  branch permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>MERGE UP THE PULL REQUEST / BRANCH</h3>\n<ol start=\"5\">\n<li>Checkout a new branch to hold your changes. This branch should not be pushed, but should follow the naming convention <code class=\"language-text\">PR/new-thing</code>:\n<code class=\"language-text\">$ git checkout -b PR/new-thing</code>.</li>\n<li>Now that your changes are on a branch, you can merge this into your desired branch (e.g. <code class=\"language-text\">master</code> or <code class=\"language-text\">feature/new-thing</code>). In most cases, we want to squash the changes into a single commit, though this flag can be omitted. Run:</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ git checkout master\n$ git merge --squash PR/new-thing</code></pre></div>\n<p>TEST BEFORE COMMITTING! Once you’re sure nothing breaks (test it manually, check for console errors, run the test suite), then you can commit:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ git commit\n$ git push</code></pre></div>\n<p><em>Alt 5 &#x26; 6)</em> Steps 4 and 5 can be replaced, as it is not necessary to checkout changes to a branch before merging. Alternatively, to merge into <code class=\"language-text\">master</code> you use the following commands:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ git checkout master\n$ git merge --squash FETCH_HEAD</code></pre></div>\n<p>TEST TEST TEST, then:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ git commit\n$ git push</code></pre></div>\n<h2 id=\"making-changes-to-a-pull-request-before-merging\"><a href=\"#making-changes-to-a-pull-request-before-merging\" aria-label=\"making changes to a pull request before merging permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>MAKING CHANGES TO A PULL REQUEST BEFORE MERGING</h2>\n<p>Mistakes happen. Whether it’s a new error that’s discovered, missing documentation, or an API key that’s been committed, you can fix these before completing your merge.</p>\n<h3 id=\"method-1-persist-changes-to-the-forked-repository\"><a href=\"#method-1-persist-changes-to-the-forked-repository\" aria-label=\"method 1 persist changes to the forked repository permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>METHOD 1: Persist changes to the forked repository</h3>\n<p>You should use this method if there is an error that you wish to change immediately.</p>\n<p>Fetch and checkout the new commits in the same way. Run:\nUsing SSH:\n<code class=\"language-text\">$ git fetch git@bitbucket.org:emilyemorehouse/cuttle-repo.git feature/new-thing</code>\nUsing HTTPS:\n<code class=\"language-text\">$ git fetch https://bitbucket.org/emilyemorehouse/cuttle-repo feature/new-thing</code></p>\n<p>Then:\n<code class=\"language-text\">$ git checkout FETCH_HEAD</code>.</p>\n<p>Make any changes then commit and note the commit ID:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ git commit -m &quot;[#XXXXXX] fixed the thing&quot;\n[detached HEAD 8bb13a2] [#XXXXXX] fixed the thing\n 1 file changedundefined 1 insertion(+)</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ git checkout master\n$ git merge 8bb13a2\n$ git push</code></pre></div>\n<h3 id=\"method-2-make-the-changes-mid-merge\"><a href=\"#method-2-make-the-changes-mid-merge\" aria-label=\"method 2 make the changes mid merge permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>METHOD 2: Make the changes mid-merge</h3>\n<p>You can also simply make changes during Step 6 while testing your merge. Changes made here will not have an explicit commit and will not be included in the automatic merge commit message though, so it’s harder to track down if you ever need to track down changes in your commit logs.</p>","timeToRead":3,"excerpt":"For this example, we’ll use the repository ‘cuttle-repo’ from Cuttlesoft that has been forked by user emilyemorehouse. The repository URL of…","frontmatter":{"title":"Completing Pull Requests Locally from Bitbucket Using Git","cover":"https://images.unsplash.com/photo-1475706398693-8250350bc704?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2250&q=80","date":"2017-01-22","category":"tutorial","tags":["git","workflow"]},"fields":{"slug":"/blog/007-completing-prs-locally-from-bitbucket/","date":"2017-01-22T07:00:00.000Z"}}},"pageContext":{"slug":"/blog/007-completing-prs-locally-from-bitbucket/"}}}