Git Rebase

Today I learned about Git Rebase while making a code contribution (commit) to the Jetpack project on Github.

I had some issues setting up the Jetpack dev environment. The yarn build command wasn’t working as expected.

I tried fixing this by installing command line tools and XCode on Mac but that didn’t help. Digging things further, I realised yarn build worked fine on the master branch but was returning errors on the custom branch (the branch that I was currently working on).

To fix this, I thought it’d be nice if there was a way to reset my custom branch to the master branch and re-apply all the changes I had done so far. This would give me a branch that’s updated with the master branch along with the changes I had done so far on the custom branch.

Turns out, this can be achieved by running git rebase master command. I learned this from this StackOverflow post, which says:

git rebase master does what you’re asking for — takes the changes on the current branch (since its divergence from master) and replays them on top of master, then sets the head of the current branch to be the head of that new history. It doesn’t replay the changes from master on top of the current branch.

That fixed the issue. The command yarn rebuild worked just fine after I rebased my current branch with master 🙂