Skip to content
Author Micah Cambre

keeping git repository in sync after forking

With my recent motivation to renew this site, I’ve built the visuals on the site from scratch, using what’s called a starter theme, with Sage. In order to build upon this theme, and for increasing interactivity to the greater internet, I’m applying principles and ideas I’ve learned from the Indieweb community.

As I’ve been integrating new features into Sage, I’m essentially logging the base changes I’m making to Sage and have forked the Sage repository into an Indieweb version that I’ve named Sage Indieweb.

I had a few goals in creating this new repository (repo):

  • Update Sage to include updated Microformats (Indieweb requirement)
  • Make minimal updates to the original code
  • Non-destructively add other code changes using WordPress specific functions and hooks
  • Provide a central repository to keep track of theme updates that might help other WordPress theme developers to update their own themes
  • Keep Sage Indieweb in sync with the Sage 9 point releases

The last bullet point took me months to figure out how to accomplish without spending hours making manual copy and paste of the various updates. This fork started with Sage version 9.0.5 and I’ve recently updated it to 9.0.7 (latest in the master branch to be correct) using a series of commands using git that took a lots of trial and error. I had to piece together a bunch of Stack Overflow answers and Git tutorials to make this work and even what I’m documenting might not be as efficient as it could be.

After forking Sage 9.0.5 and converting it into a new repo, I made several changes that I added to the repo over the course of a few months. But my speed was not just from lack of coding time, it was also anxiety from watching the original Sage repository make progress but not knowing how to get to these new changes without manual work.

A couple of weeks ago, I had the itch to finally update Sage Indieweb to match Sage 9.0.7, two more point releases than the fork. I dove in further to learn more about a few git commands: git remote, git fetch, and git cherry-pick. Finally, I pushed through a lot of research and came up with what I hope will be a good workflow to update other repositories in this situation.

The new Sage Indieweb repo I created had all the same history up to the 9.0.5 release, which makes sense for me to be able to just merge the newer updates to Sage directly into Sage Indieweb. However, with more reading, I realized this wasn’t a good option because I want to keep the git history clean.

Here was my rough mental model:

  1. Add a remote repository for Sage to associate to my repository, maybe using git subdirectory or subtree, maybe just remote branch
  2. Fetch the updated changes to Sage
  3. Squash the newer commits into one combined commit
  4. Merge squashed commit bundle into my repository

Unfortunately, I was a little off and the above was tweaked:

  1. Add a remote repository for Sage
  2. Fetch the updated changes to Sage
  3. Cherry pick a range of commits into Sage Indieweb
  4. Squash the cherry picked commits into one combined commit
  5. Update Github repository

Let’s go through every step.

Add a remote repository for Sage

I was certain there had to be a way for me to associate the new repo with the original but nothing described what I wanted. Both repos are, effectively, unrelated since I took the forked repo, removed all the history, and made it into a new standalone repository on Github with a clean git history.

$ git remote -v
origin	https://github.com/asuh/sage-indieweb.git (fetch)
origin	https://github.com/asuh/sage-indieweb.git (push)

After trial and error, I realized it was possible to just ad a new remote repository with a new name. This is how I associated it with the new repo.

$ git remote add sage https://github.com/roots/sage.git

$ git remote -v
origin	https://github.com/asuh/sage-indieweb.git (fetch)
origin	https://github.com/asuh/sage-indieweb.git (push)
sage	https://github.com/roots/sage.git (fetch)
sage	https://github.com/roots/sage.git (push)

Okay, so let’s get everything from the repo.

Fetch the updated changes to Sage

There might be a more efficient way for me to do this but I just fetched all of Sage including its various branches and tags.

git fetch sage

This made me nervous, maybe there was now some changes but the coast was clear.

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Now comes the trickiest part.

Cherry pick a range of commits into Sage Indieweb

Originally, I was hoping I could just squash all the newest commits down into one commit and just merge that new commit. Maybe this is possible but I didn’t see a straightforward way to do this without a using a merge command, but even that didn’t appear good.

I found out that it’s possible to cherry pick a range of commits. Lots of trial and errors in practice since I wasn’t sure if I needed additional flags. In fact, I was hoping I could just flag something like --squash into the cherry pick command to squash everything together as I’m cherry picking that range, but that was not possible.

$ git cherry-pick 37c7e0d..19057f6
error: could not apply 9040a3d... Normalize and enforce single quotes in scripts
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'

Darn, it’s a merge conflict.

So what I’m telling git to do is grab all the commits from just after 9.0.5, which is a SHA-1 of 37c7e0d all the way to the latest commit, separated by the two dots which signifies everything in between these two commits.

You can see the first of many merge conflicts or issues that stopped the process along the way. The errors were either because of my Indieweb updates to Sage or because of remote merges that occurred on the Sage repo.

Wait, what? Cherry picking doesn’t apply merges based from the remote repo because they are commits with more than one parent. I had to actually choose how to merge in the remote merges. So confusing.

So, when I got a regular merge conflict like the one above, I went to my editor, made the updates and necessary changes, then continued the cherry picking process.

$ git cherry-pick --continue

When I came across a merge conflict based on a remote merge, it was more complicated. Lots of wrong commands helped me learn I had add a flag to choose what’s called the mainline, which lets git know which of the parents to add. It’s still confusing to me but you can read more about it.

$ git cherry-pick -m 1 93ee95d
On branch master
Your branch is ahead of 'origin/master' by 9 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 93ee95d.

nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

If you wish to skip this commit, use:

    git reset

Then "git cherry-pick --continue" will resume cherry-picking
the remaining commits.

Oh man, now I’m confused again. But after more referencing the logs, researching what’s going on and getting more errors, I decided to just $ git commit --allow-empty to get past this since I likely had the commit in there.

All in all, I had a lot of $ git log and $ git cherry-pick --continue to get through this. In the end, I verified that everything was brought over.

Squash the cherry picked commits into one combined commit

While the command $ git merge --squash is what I wanted to use, I ended up having to use $ git rebase -i 32bb46d, 32bb46d being the latest commit made, to date, to the Sage master branch in order to squash everything down to one combined commit. I need to read more to see if the commit is required because it would have been nice to just $ git rebase -i.

I looked through the log of what I committed and the log needed to be cleaned up as well. So I edited it with $ git commit --amend since I hadn’t pushed it to the repo to give it an appropriate title.

Update Github repository

Once all of this was cleaned up and the history looks good, off to the repository it goes. $ git push and off it goes!

Thoughts about this process

This was an exercise in frustration as I was trying to figure out how to do all of this. Git is a fascinating tool to accomplish a lot especially when working on teams and using feature branches.

  • $ git log is an ok default but there’s so much more I could use it for visually
  • I wish upstream merges weren’t so tough to merge into local repositories. This use of mainline is not obvious and I feel like there’s UX improvement that could be shown here, similar to an interactive rebase view

The learning process isn’t always pretty but I have a better grasp at other concepts that’ll spin off from merging and fetching.

Bookmarked For Earthquakes, Forget The ‘Go-Bag.’ Here’s How To Prepare by Arwen Champion-Nicks

As long as I live in earthquake zones, I can’t get enough reminders to prepare and how to prepare.

FEMA B 526 Earthquake Safety Checklist

Quoted I Gave a Bounty Hunter $300. Then He Located Our Phone (Motherboard)

T-Mobile, Sprint, and AT&T are selling access to their customers’ location data, and that data is ending up in the hands of bounty hunters and others not authorized to possess it, letting them track most phones in the country.

This type of story makes me want to embrace my inner Luddite. The fact that phone locations are routinely tracked and sold to third parties is only the tip of an enormous privacy-is-dead iceberg that continues on with Facebook freely giving access to our data to third parties and onto Google knowing everything that we do online based on its trackers like Google Analytics. It doesn’t matter how much I lock down the technology I use, I’ve been concerned for years; the last three years I’ve been as active as I can to keep as much of that control as possible.

Without discontinuing the use of a smartphone that doubles as a GPS device, which is all smartphones, I don’t know of a good solution for this.

2019 – Evaluate using Sass everywhere. CSS Grid + CSS Variables cover a lot of ground. How necessary is it today? Mostly for nesting and file organization, but a build script will solve both

January rain, hard deployments, React homework, Locally ordered pizza, Gatsby upgrade, Web host creation, Thinking about Indieweb

I think this was a productive Saturday!

the web, my web, and an open web

Being back at asuh.com is satisfying. I’ve started new again, renewing a passion I once had, and I’m excited for things to come.

Before I knew it was probably my career, creating on the Internet (capital ‘I’ at the time) became a new puzzle I enjoyed solving. I spent the late 1990s and early 2000s learning to how to utilize all things digital. I was inspired by friends and industry professionals, seeing how websites gave people freedom and platforms of their own.

I was able to register this domain in 2002 after it was released by someone else who previously purchased it. This is my prized domain name since I feel a connection to the term “asuh” since the early 1990s. For the next few years, it was my digital home and where I expressed myself to broadcast to others, interested to keep up with even a small part of my life.

Things slowly changed in the MySpace days starting around 2007. I posted less here and more there, where the eyeballs and activity were focused. That participation moved over to Facebook in the late 2000s and has more or less stayed there since this year.

2012 was the year my website’s pulse stopped. One last post about my move and life change and I stopped writing. I didn’t have the desire or interest that I used to have since the online collective, all of us who go on the internet (lowercase ‘i’), was locked into social platforms. How could I find motivation to post here anymore when everyone had migrated into the various apps and sites?

Now at the end of 2018, I’m social-media-burnt-out. I’ve all but stopped posting on Facebook and Twitter except now when I post here first. I don’t enjoy the social media participation like I used to and don’t get the same feeling of enjoyment. I lost trust in most of these platforms.

For the last few years, as I’m listening to This Week in Google, I kept hearing of a movement called Indieweb about owning your data and content: taking back the control from the various “silos”. It was appealing, my ears perked up every time I heard it. So in 2017, I finally made an effort to learn more and participate. I finished a first phase of a website redesign on this site, updated existing content, added new pages and content, and now have renewed motivation.

Controlling what I do online is once again my priority. I hope to set an example here and elsewhere showing how to take back control of my online presence. By creating posts like this freely on my website, I once again give back to an open web, one which starts with me and isn’t controlled by other sites or apps.

Maybe this is just a rose-tinted view I get from my own digital bubble, but being back on here gives me an excitement I missed.

Replied to

Have you heard of @indiewebcamp? This is a growing community of web folks eager for your same hopes trying to recapture an independent web outside of social media

at test

@asuh, what happens when I link to my twitter profile using the profile name inside a post? Will that be the same as what I expect to happen on Twitter?

personal websites

Read We Should Replace Facebook With Personal Websites by Jason KoeblerJason Koebler (Motherboard)

Personal websites and email can replace most of what people like about Facebook—namely the urge to post about their lives online.

I resonate with Jason’s article having been down a similar path. However, I also see another side to this: Facebook et al are simply the next iteration of communication, sharing content that is valuable to people for a moment in time. I know there are people who put a lot of heart into what they share, would love to revisit the things they said or did. I also know many who couldn’t care less to see what they did or thought 10 or 20 years ago.

The reason siloed social media sites are, and will continue to be, popular is because silos have always been effective as a way to connect, be it from newsgroups or AOL of many years ago. I would argue many, if not most, people are only looking for instant gratification and hits of dopamine in what they do as they participate in these sites and apps. Not all need or want the ability to own their own content or understand the value in it.

For those of us who do, our personal websites are the perfect means to control what is out there. I’ve found new motivation to help give those like me the means to take this control back.

the huell howser legacy is online!

Bookmarked Huell Howser Archives at Chapman University by an author

Gold has struck! For those who’ve never heard of the enthusiastic Huell Howser, he created a show that ran for years on California’s PBS stations which highlighted his trips and research to various locations around the state.

Because of his show, I visited a few places in the state that I would not have otherwise thought about or known. In October of 2017, for example, we went apple picking about a couple hours east of LA and it was a really nice way to get out of LA proper and enjoy one of the many things that California has.

If you want a taste of what kind of show he made, try the episode about the Hollywood Sign.

He left behind such a great legacy and now I can see more episodes that I missed through the years!