Skip to content

⭐️ Lean Branching - a git branching model to keep clean history #1432

@DanPristupov

Description

@DanPristupov

We are thinking about adding to Fork a feature which would help teams to keep clean history.

As you know it's pretty difficult to have a clean history in git. I've got some ideas and tricks how that can be achieved. Briefly: create a separate branch for each feature, synchronize your changes with the main branch using rebase and merge back to main at the end. My point of view is similar to what Chris Manson suggests in his great article (https://simplabs.com/blog/2021/05/26/keeping-a-clean-git-history/, I really recommend to read it if you haven't yet).

Here's an example of a decent git history:

Screenshot 2022-01-20 at 15 58 13

The commit history may look simple and clear, but making it so is surprisingly difficult and requires the use of some advanced (and dangerous) git features. In particular:

  • rebase (to rebase on main)
  • force push with lease (to update the remote tracking reference after the rebase)
  • hard reset (if something went wrong and we want to start from scratch).

We are thinking about adding to Fork the ability to easily make those operations and perform dangerous things automatically (without hiding them, though!). Something like git-flow, but not so complicated and with a dedicated sync option. We called it "Lean branching" trying to reflect the approach but may be there could be a better name.

Goals:

  • Be simple
  • Keep history clean by default
  • Do not introduce a naming convention. Fork can work with main, develop or master.
  • Intuitive for advanced users
  • Easy to explain to non-developers

The workflow is supposed to be like the following:

  • Start a branch on main
  • Commit changes. Sync with main as often as possible to minimize future conflicts
  • When the work is done, finish the branch by merging it into main

So, there are just 3 actions:

Screenshot 2022-01-20 at 16 33 42

1. Start new branch
Create and checkout new branch on main or origin/main (depends on which one is ahead)

2. Sync active branch

  • rebase on the remote tracking branch (if needed)
  • rebase on main (if needed)
  • restore the remote tracking branch position on the new location using force push. So, if it was 2 commits behind the branch, it will remain 2 commits behind after the sync

If the active branch is main, sync will simply rebase it on origin/main

3. Finish active branch

  • merge the current branch into main, but use fast-forward if the branch consists of a single commit.
    precondition: main must be in sync with origin/main

Simple example:

I've finished working on FW-433 and want to merge the changes into master:
Screenshot 2022-01-20 at 16 10 40

Sync FW-433 with master first:
Screenshot 2022-01-20 at 16 26 53

Finish FW-433:
Screenshot 2022-01-20 at 16 27 16

Now I can test if everything works properly and then push master.

A few notes:

  • Your changes will not be pushed or fetched automatically. You must do that yourself, same as you do now.
  • All 3 actions are available in the Branch dropdown on the toolbar in Fork
  • The underlying git commands can be seen in the activity manager if you click on the status control on the toolbar

Tanya and I have been using this feature 'as users' for some time and it works really well for us.

It would be great if you could try it and let us know what you think.

You can download the build here: https://cdn.fork.dev/prerelease/ForkWin-1.69.10.zip. Extract it somewhere and run fork.exe.

Use with caution, it's still in beta.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions