This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
oliverdavies.uk-old-sculpin/docs/blog/2015/06/18/updating-forked-repositories-on-github/index.html

308 lines
15 KiB
HTML
Raw Normal View History

2017-07-10 21:28:39 +00:00
<!DOCTYPE html>
<html class="no-js" lang="en-GB">
<head>
<title>Updating Forked Repositories on GitHub | Oliver Davies</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="I just had to update a repo that I forked on GitHub. This is how I did it. Did I do it the correct way?">
2017-07-12 06:22:51 +00:00
<meta property="og:url" content="https://www.oliverdavies.uk/blog/2015/06/18/updating-forked-repositories-on-github">
2017-07-10 21:28:39 +00:00
<meta property="og:title" content="Updating Forked Repositories on GitHub"/>
2017-07-12 06:22:51 +00:00
<meta property="og:image" content="https://www.oliverdavies.uk/assets/images/me-precedent.jpg"/>
2017-07-10 21:28:39 +00:00
<meta property="og:image:height" content="327"/>
<meta property="og:image:type" content="image/jpg">
<meta property="og:image:width" content="327"/>
2017-07-12 06:22:51 +00:00
<link rel="stylesheet" href="https://www.oliverdavies.uk/assets/css/main.css">
<link rel="stylesheet" href="https://www.oliverdavies.uk/assets/css/blog-post.css">
2017-07-10 21:28:39 +00:00
<link rel="apple-touch-icon" href="/assets/images/me-precedent.jpg?s=57" sizes="57x57">
<link rel="apple-touch-icon" href="/assets/images/me-precedent.jpg?s=114" sizes="114x114">
<link rel="apple-touch-icon" href="/assets/images/me-precedent.jpg?s=72" sizes="72x72">
<link rel="apple-touch-icon" href="/assets/images/me-precedent.jpg?s=144" sizes="144x144">
<link rel="apple-touch-icon" href="/assets/images/me-precedent.jpg?s=60" sizes="60x60">
<link rel="apple-touch-icon" href="/assets/images/me-precedent.jpg?s=120" sizes="120x120">
<link rel="apple-touch-icon" href="/assets/images/me-precedent.jpg?s=76" sizes="76x76">
<link rel="apple-touch-icon" href="/assets/images/me-precedent.jpg?s=152" sizes="152x152">
<link rel="icon" href="/assets/images/me-precedent.jpg?s=160" sizes="160x160">
<link rel="icon" href="/assets/images/me-precedent.jpg?s=96" sizes="96x96">
<link rel="icon" href="/assets/images/me-precedent.jpg?s=32" sizes="32x32">
<link rel="icon" href="/assets/images/me-precedent.jpg?s=16" sizes="16x16">
</head>
<body class="">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
2017-07-12 06:22:51 +00:00
<a class="navbar-brand" href="https://www.oliverdavies.uk/">Oliver Davies</a>
2017-07-10 21:28:39 +00:00
</div>
<div id="navbar" class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li class="">
<a href="/">About</a>
</li>
<li class="">
<a href="/experience">Experience</a>
</li>
<li class="">
<a href="/testimonials">Testimonials</a>
</li>
<li class="">
<a href="/talks">Talks</a>
</li>
<li class="active">
<a href="/blog">Blog</a>
</li>
<li class="">
<a href="/contact">Contact</a>
</li>
</ul>
</div> </div>
</nav>
<div class="container">
<div class="row">
<main class="col-md-9">
<h1>Updating Forked Repositories on GitHub</h1>
2017-07-11 17:57:51 +00:00
<p class="posted text-light">18th June 2015</p>
2017-07-10 21:28:39 +00:00
<h2 id="sculpin">Sculpin</h2>
<p>People may or may not know, but this site runs on <a href="https://sculpin.io/">Sculpin</a>, a PHP based static site generator (this may be the first time that I've mentioned it on this site). The source code is hosted on <a href="https://github.com/opdavies/oliverdavies.uk">GitHub</a>, and I've listed the site on the <a href="https://sculpin.io/community/">Community page</a> on the Sculpin website.</p>
<p>To get it there, I forked the <a href="https://github.com/sculpin/sculpin.io">main sculpin.io repository</a> so that I had <a href="https://github.com/opdavies/sculpin.io">my own copy</a>, created a branch, made my additions and submitted a pull request. Easy enough!</p>
<h2 id="new-domain">New Domain</h2>
<p>In the last week or so, I've changed this site URL from .co.uk to just .uk, and also updated the GitHub repo URL to match, so I wanted to update the Community page to use the correct URL.</p>
<p>There had been commits to the main repo since my pull request was merged, I didn't want to delete my repo and fork again, and making any changes against and old codebase isn't best practice, so I wanted to merge the latest changes into my forked repo before I did anything else - just to check that I didn't break anything!</p>
<h2 id="updating-my-local-repo">Updating my Local Repo</h2>
<p>I had a quick look for a <em>Update my fork</em> button or something, but couldn't see one to I added the main repository as an additional remote called <code>upstream</code> and fetched the changes.</p>
<pre><code class="language-bash">$ git remote add upstream https://github.com/sculpin/sculpin.io.git
$ git fetch upstream
remote: Counting objects: 33, done.
remote: Total 33 (delta 6), reused 6 (delta 6), pack-reused 27
Unpacking objects: 100% (33/33), done.
From https://github.com/sculpin/sculpin.io
* [new branch] master -&gt; upstream/master
* [new branch] pr/4 -&gt; upstream/pr/4
</code></pre>
<p>Now my local site knows about the upstream repo, and I could rebase the changes (<code>git pull upstream master</code> should have worked too) and push them back to origin.</p>
<pre><code class="language-bash">$ git rebase upstream/master
First, rewinding head to replay your work on top of it...
...
Fast-forwarded master to upstream/master.
$ git push origin master
</code></pre>
<p>This seems to have worked OK - the commits are still authored by the correct people and at the correct date and time - and I went ahead and created a new feature branch and pull request based on that master branch.</p>
<figure>
<img src="/assets/images/blog/forked-github-repo-commits.png" alt="The commits on my master branch after rebasing">
<figcaption>The commits on my forked master branch after rebasing and pushing. All good!</figcaption>
</figure>
<figure>
<img src="/assets/images/blog/my-commit-to-the-rebased-branch.png" alt="The new feature branch with my additional commit.">
<figcaption>The new feature branch with the new commit.</figcaption>
</figure>
<h2 id="is-there-a-better-way%3F">Is There a Better Way?</h2>
<p>Did I miss something? Is there a recommended and/or better way to update your forked repos, maybe through the UI? Please <a href="https://twitter.com/?status=Rebasing GitHub Forks: @opdavies">send me a tweet</a> with any comments.</p>
<h2 id="update%3A-rebasing-in-phpstorm">Update: Rebasing in PhpStorm</h2>
<p><strong>December 2015:</strong> Ive found that PhpStorm has an option available to rebase a fork from within the IDE. This is within the <em>VCS</em> > <em>Git</em> menu.</p>
<p>I believe that it will use an existing "upstream" remote if it exists, otherwise it will add one automatically for you, linking to the repository that you forked from.</p>
<p>Once youve completed the rebase, you can then push your updated branch either from the terminal, or using the <em>Push</em> command from the same menu.</p>
<p><img src="/assets/images/blog/github-fork-rebase-phpstorm.png" alt="Rebasing a forked repository in PhpStorm using the VCS menu." /></p>
<p>It would be great to see something similar added to <a href="https://hub.github.com">hub</a> too (Ive created <a href="https://github.com/github/hub/issues/1047">an issue</a>)!</p>
<h2 id="resources">Resources</h2>
<ul>
<li><a href="http://blog.jetbrains.com/idea/2011/02/advanced-github-integration-rebase-my-github-fork/">PhpStorm - Advanced GitHub Integration: Rebase My GitHub Fork (blog post)</a></li>
<li><a href="https://www.youtube.com/watch?v=Twy-dhVgN4k">Rebasing a GitHub fork inside PhpStorm (video)</a></li>
<li><a href="https://hub.github.com">hub</a> - makes Git better with GitHub</li>
</ul>
<p class="tags">
Tags:
2017-07-12 06:22:51 +00:00
<a href="https://www.oliverdavies.uk/blog/tags/git">git</a>, <a href="https://www.oliverdavies.uk/blog/tags/github">github</a>, <a href="https://www.oliverdavies.uk/blog/tags/phpstorm">phpstorm</a>, <a href="https://www.oliverdavies.uk/blog/tags/sculpin">sculpin</a> </p>
2017-07-10 21:28:39 +00:00
<div class="post-pager is-flex">
<div class="is-half">
<a href="/blog/2015/04/03/how-to-define-a-minimum-drupal-core-version">
&laquo; How to Define a Minimum Drupal Core Version
</a>
</div>
<div class="is-half text-right">
<a href="/blog/2015/07/19/sculpin-twig-resources">
Sculpin and Twig Resources &raquo;
</a>
</div>
</div>
<div class="about-author">
<h2>About the Author</h2>
2017-07-12 06:24:51 +00:00
<img src="//www.oliverdavies.uk/assets/images/me-precedent.jpg" alt="Picture of Oliver" class="img-circle">
2017-07-10 21:28:39 +00:00
<p>Oliver Davies is a Web Developer, System Administrator and Drupal specialist based in the UK. He is a Senior Developer at <a href="https://microserve.io">Microserve</a> and also provides freelance consultancy services for Drupal websites, PHP applications and Linux servers.</p>
</div>
</main>
<div class="col-md-3">
<div class="panel badges text-center">
<a class="badge--da-member" href="https://assoc.drupal.org/membership" title="Im a Drupal Association member.">
<img
2017-07-12 06:24:51 +00:00
src="//www.oliverdavies.uk/assets/images/da-individual-member.png"
2017-07-10 21:28:39 +00:00
alt="Drupal Association Individual Member"
width="152"
>
</a>
<a href="http://drupalcores.com/#opdavies">
<img
alt="I built Drupal 8 with hand holding a wrench on blue background"
2017-07-12 06:24:51 +00:00
src="//www.oliverdavies.uk/assets/images/drupal-8.jpg"
2017-07-10 21:28:39 +00:00
/>
</a>
<img
2017-07-12 06:24:51 +00:00
src="//www.oliverdavies.uk/assets/images/badges/acquia-certified-developer-drupal-8.png"
2017-07-10 21:28:39 +00:00
alt="Acquia Certified Developer - Drupal 8 Exam Badge"
height="147" width="147"
/>
<a href="http://conference.phpnw.org.uk/phpnw17">
2017-07-12 06:24:51 +00:00
<img src="//www.oliverdavies.uk/assets/images/badges/phpnw17.png" alt="">
2017-07-10 21:28:39 +00:00
</a>
</div>
<div class="availability panel panel-default">
<div class="panel-heading">Availability</div>
<div class="panel-body">
<p>
<i class="fa fa-thumbs-o-up text-warning"></i>
Currently have limited part-time capacity
</p>
<p>
<i class="fa fa-thumbs-o-down text-danger"></i>
Currently no spare full-time capacity.
</p>
</div>
</div>
<div class="latest-posts panel panel-default">
<div class="latest-posts__heading panel-heading">Latest blog posts</div>
<ul class="list-group">
<li class="post list-group-item">
2017-07-13 21:19:23 +00:00
<span class="post__title">
<a href="/blog/2017/07/13/publishing-sculpin-sites-with-github-pages">
Publishing Sculpin Sites with GitHub Pages
</a>
</span> -
<span class="post__date">13th July, 2017</span>
</li>
<li class="post list-group-item">
2017-07-10 21:28:39 +00:00
<span class="post__title">
<a href="/blog/2017/06/09/introducing-the-drupal-meetups-twitterbot">
Introducing the Drupal Meetups Twitterbot
</a>
</span> -
<span class="post__date">9th June, 2017</span>
</li>
<li class="post list-group-item">
<span class="post__title">
<a href="/blog/2017/05/20/turning-drupal-module-into-feature">
Turning Your Custom Drupal Module into a Feature
</a>
</span> -
<span class="post__date">20th May, 2017</span>
</li>
</ul>
</div>
</div>
</div> </div>
<footer class="container">
<p class="copyright">
&copy; 2010-2017 Oliver Davies. Built with <a href="https://sculpin.io">Sculpin</a>.
</p>
<div class="meetups">
<h2>Things that I organise</h2>
<ul>
<li class="meetups--drupal-bristol">
<a href="http://www.drupalbristol.org.uk" title="Drupal Bristol">
2017-07-11 06:34:02 +00:00
<img
2017-07-12 06:24:51 +00:00
src="//www.oliverdavies.uk/assets/images/meetups/drupal-bristol.jpeg"
2017-07-11 06:34:02 +00:00
alt="Drupal Bristol logo"
>
2017-07-10 21:28:39 +00:00
</a>
</li>
<li class="meetups--drupalcamp-bristol">
<a href="http://www.drupalcampbristol.co.uk" title="DrupalCamp Bristol">
2017-07-11 06:34:02 +00:00
<img
2017-07-12 06:24:51 +00:00
src="//www.oliverdavies.uk/assets/images/meetups/drupalcamp-bristol.png"
2017-07-11 06:34:02 +00:00
alt="DrupalCamp Bristol logo"
>
2017-07-10 21:28:39 +00:00
</a>
</li>
<li class="meetups--phpsw">
<a href="http://phpsw.uk" title="PHPSW">
2017-07-11 06:34:02 +00:00
<img
2017-07-12 06:24:51 +00:00
src="//www.oliverdavies.uk/assets/images/meetups/phpsw.jpeg"
2017-07-11 06:34:02 +00:00
alt="PHPSW logo"
>
2017-07-10 21:28:39 +00:00
</a>
</li>
</ul>
</div>
</footer>
2017-07-12 06:22:51 +00:00
<script src="https://www.oliverdavies.uk/assets/js/site.js"></script>
2017-07-10 21:28:39 +00:00
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-11967257-1', 'auto'); ga('send', 'pageview');</script>
</body>
</html>