0

Situation:

  • I have a repository with commits up to 1234
  • Someone forks it and adds a commit abcd and sends a PR
  • I like to rebase it instead of merge the branch as the branches are not diverged
  • I git cherry-pick the commit, but the new commit is now wxyz as git adds Committer and CommitDate fields and probably some other metadata

My current workaround is to manually git fetch their repo and then git reset --hard onto commit abcd. Afterward I can push my branch to my repo.

It would be especially nice, if I could update the branch from a GitHub PR without resorting to manually fetching and pushing just to add a single commit from a GitHub PR to my repo.

allo
  • 3,955
  • 8
  • 40
  • 71
  • Your current approach removes all commits that happened in your repository after `1234`, unless you mixed up `reset --hard` and `rebase`. Other than that, check out fast-forward merge and/or try "Squash and merge"/"Rebase and merge" modes in GitHub PRs. – yeputons Dec 28 '22 at 15:55
  • 1
    Sounds like you're looking for Git's default behavior, fast-forward merge. – jthill Dec 28 '22 at 16:06
  • @yeputons I am talking about a fork that is not diverged, i.e., no commits happened to my repo since the user forked it. Otherwise it would be a rebase anyway and change commit IDs because of the commits that were added in between. – allo Dec 28 '22 at 16:08
  • @jthill This works for things commited to my repo, but from other repos it creates merge commits that I want to avoid. – allo Dec 28 '22 at 16:09
  • Can you clarify this statement: "I like to rebase it instead of merge the branch as the branches are not diverged". Normally, the opposite would be true, i.e. you rebase when they diverge and otherwise merge (with the option to either fast-forward or force a merge commit depending on the situation). – TTT Dec 28 '22 at 17:50
  • @TTT I just want to append the new commit to my branch. Without any changes. I think the whole problem could be that only github prefers to merge branches instead of using fast-forward. – allo Dec 29 '22 at 20:58
  • @torek You can do this, if you have fun doing it, but it is not relevant to the question. And the question is already answered. And I already answered your previous comments. – allo Jan 02 '23 at 11:54

1 Answers1

2

You can add their repo as an origin, fetch all commits, and use git merge --ff-only abcd.

ruohola
  • 21,987
  • 6
  • 62
  • 97