GitHub Fork and Pull Request Workflow - Quick Reference Guide
github.com
github.com
I git clone'd the project, built it, noticed something small, fix it locally, and then decide OK I'll just send this up real quick. oh crap. NOPE I have to do a bunch of GitHub crap with forking and merging to get it back to the master tree. Annoying.
Forking and merging is perfectly fine for regular contributions, but for smaller one-time type fixes it's just annoying.
https://github.com/search?q=is:pr+author:YOURNAME&type=Issue...
Here's how to see all your open PRs:
https://github.com/search?q=is:pr+is:open+author:YOURNAME&ty...
Replace YOURNAME with your GitHub handle, or pick your colleagues names.
Patches require you to share the patch somewhere. Your just sharing the patch to a different interface.
Unless you know something I don't?
I think allowing patches is just a better solution here.
Are there any good reasons why someone should try to rebase and merge (fast-forward) a pull request to avoid a merge commit? It involves more steps than the method which creates a merge commit. What benefits warrant these additional steps?
A linear history is helpful when debugging since it makes git bisect a lot easier. Having individual PR commits in the history makes git bisect useless since it’s unfortunately common for individual PR commits to leave the system in a broken state.
How do you deal with cases where your changes require more than a single commit? Some changes are easier to review when they're separated into several logical commits rather than having one giant diff from a single commit.
The nice part of this workflow is that the changes are all squashed into a single commit in the trunk, but there’s always a link to the pull request where you can see the individual commits pre-squash.
I've always thought of it as a way to effectively create a branch, do your work, and fast-foward merge it back in to the main branch without having any other work included in it.
To put it another way, let's say you create a fork, do your work, and in the interim, several other contributors do the same thing and merge their work back into the main repo. Now, you could merge the mainline back into your fork and have a merge commit in your private branch that shows the changes that the other contributors made since you created your branch, or you could merge your branch back into the main branch at the end and have it show that it branched off earlier than the current head of the main branch.
In the first case, you now have a commit that shows changes that you didn't actually make. In the second case, it shows that you didn't base your work on the latest version of the main branch.
In contrast, if you rebase and only merge your work into the main branch via a fast-forward merge, your branch will only show commits that you made and it will effectively show that it was based on the latest version of the main branch before it was merged back in.
Merging does create a merge commit which is sometimes annoying (when you are merging a single-line commit, for example). It does however preserve full history.
Frequently, I see a commit history like:
Implemented feature
Forgot semi-colon
Fixed syntax error
Addressing review comments
Removed unnecessary method
History like that, other than the initial commit, is not very useful. It makes more sense to rebase to clean up the commit history such that it becomes a logical series of commits, which can then be viewed via git log or git blame.If the push fails because the master has changed during the few minutes you spent in rebasing, just rebase again on the most current master and push again. No force-push is required.
Relevant excerpt:
> If you set your pages and repositories to be viewed publicly, you grant each User of GitHub a nonexclusive, worldwide license to use, display, and perform Your Content through the GitHub Service and to reproduce Your Content solely on GitHub as permitted through GitHub's functionality (for example, through forking).
For those interested, GitHub's entire TOS is written in a very approachable way.
Does anyone know anyway to look at the linear commit history alone (not GitHub) and tell where a pull request was merged and who merged it?
If each commit notes the issue number in its comment (“Add indentation and trailing white space check to CI [#123]”) then you can see easily when each merge occurred by issue number.
Additionally in GitHub there are conveniences built from these little conventions. The “#123” is displayed as a hyperlink to the issue, and merging a commit that has “Fix #123” automatically closes the issue.
In cases where a feature is big enough to justify multiple commits for clarity, you can mention “#123” in all but the last commit, and “fix #123” in the final commit. Doing so partitions the linear history.
In fact, if someone else notices and fixes a regression caused by the merge, they can push additional commits later on but mention “#123” in their commit as well for documentary purposes. Seeing downstream commits “out of sequence” but with some earlier issue number is a clue this was probably a regression.
The person who merged the commit appears as the committer name only if the rebase led to a change in the SHA1 hash of the commit.
If the pull request branch is already based on master and up-to-date with master, then "git checkout master; git merge pr" performs a fast-forward merge without altering any commits. The SHA1 hash of the commits in the pull request do not change. The merger's name does not appear anywhere because the merger has not done anything except fast-forwarding master.
IMO it's far preferable to have an explicit "merge" commit referencing the PR in question, whether that that is a --no-ff merge or a single linear squashed commit.