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:
- Make changes and follow the usual workflow.
- gt create to create a patch and/or gt modify to commit changes.
- gt restack to fix your stack.
- gt bottom
- gt push
- gt up
- Repeat steps 5-6 until you have pushed all of your branches.
- Generate pull requests for all of your commits on your forked repo.
- Run git genpullmsg bottombranch topbranch to generate the markdown comment to be added to the pull requests.
- 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:
