Skip to content

Instantly share code, notes, and snippets.

@MikeRatcliffe
Created September 19, 2024 22:08
Show Gist options
  • Save MikeRatcliffe/a5928823f2fbab0a71ffc32cef6e57c5 to your computer and use it in GitHub Desktop.
Save MikeRatcliffe/a5928823f2fbab0a71ffc32cef6e57c5 to your computer and use it in GitHub Desktop.

I have create a git alias to help those contributing to open source repositories using Graphite on forked commits (feedback on this process is welcome):

genpullmsg = "!f() { \echo \"This is one pull request in a stack... they are all based on top of each other, so the order is important.\"; \
    echo \"\"; \
    echo \"The advantage of this approach is that you are guaranteed no conflicts and reviews should be shorter.\"; \
    echo \"\"; \
    echo \"Review each patch and merge before you move on to the next, this way, nothing will break and the code will be easier to review.\"; \
    echo \"\"; \
    echo \"Start from the bottom (above main) and work your way up the stack until you reach the top.\"; \
    echo \"\"; \
    commitids=$(git log --graph --oneline --boundary --ancestry-path $1...$2 --pretty=format:\"%h\"  | awk -F' ' '{print $2}'); \
    bottomcommitid=$(git log $1 --pretty=format:\"%h\" -1); \
    bottompushid=$(git ls-remote upstream 'pull/*/head' | grep -e \"$bottomcommitid\" | awk -F/ '{print $3}'); \
      for commitid in $(echo \"$commitids\"); do \
        pushid=$(git ls-remote upstream 'pull/*/head' | grep -e \"$commitid\" | awk -F/ '{print $3}'); \
        if [ \"$pushid\" != \"$bottompushid\" ]; then \
          echo \"* **#$pushid**\"; \
        else \
          echo \"* **#$pushid** 👈\"; \
        fi \
      done \
}; f"

You need to add the upstream remote (the repo that you want to create pull requests for) to your fork: git remote add upstream https://github.com/targetuser/targetrepo.git

The workflow:

  1. Make changes and follow the usual workflow.
  2. gt create to create a patch and/or gt modify to commit changes.
  3. gt restack to fix your stack.
  4. gt bottom
  5. gt push
  6. gt up
  7. Repeat steps 5-6 until you have pushed all of your branches.
  8. Generate pull requests for all of your commits on your forked repo.
  9. Run git genpullmsg bottombranch topbranch to generate the markdown comment to be added to the pull requests.
  10. Paste the comment into each request moving the hand icon as you go.

It's a bit of a pain, but you do get the awesome stacks that we all love ;)

It looks like this:

Screenshot 2024-09-19 at 22 56 54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment