Linear History and Rebasing
First off—why do we enforce linear history and rebasing?
The commit guide linked from the official Google stylesheet explains it well:
"A well-cared for log is a beautiful and useful thing. git blame, revert, rebase, log, shortlog and other subcommands come to life. Reviewing others' commits and pull requests becomes something worth doing, and suddenly can be done independently. Understanding why something happened months or years ago becomes not only possible but efficient."
Here are some pros and cons, these are by no means exhaustive, just a selection of important ones.
Pros:
- The git log/history becomes a powerful tool for understanding project evolution.
- Encourages thoughtful commits—rebasing pushes developers to organize their commits locally
Cons:
- Rebase rewrites history which can be risky when done on shared branches
Note
At Neroli's Lab, we discourage sharing branches directly. Instead, collaborate through pull requests. For feature work, please use your own branches and open pull requests into the feature branch.
How to Rebase Your Fork
Follow these steps to keep your fork up-to-date and our commit history linear:
1. Fork and Clone the Repository
- Fork the repo on GitHub: nerolis-lab/nerolis-lab
- Then clone your fork:
git clone https://github.com/<your-username>/nerolis-lab.git
cd nerolis-lab2. Add the Upstream Repository
Link your local repo to the original repository:
git remote add upstream https://github.com/nerolis-lab/nerolis-lab.git
git fetch upstream3. Create and Checkout Your Feature Branch
git checkout -b my-feature-branch4. Rebase Your Branch When the Upstream Changes
- Fetch latest changes:
git fetch upstream- Rebase your branch:
git rebase upstream/main- Resolve any conflicts:
git add <fixed-files>
git rebase --continue5. Force Push Your Rebasing Changes
Since rebasing rewrites history, you'll need to force push.
git push origin my-feature-branch --force-with-lease6. Submit Your Pull Request
Head over to GitHub and open your pull request. Whenever the main branch changes just repeat steps 4 and 5.
Final Note
Ask for Help: If you get stuck, don't hesitate to reach out. We're all here to help each other!
