0

What will be the way of clone the pull request into my repo locally? https://github.com/RoboSherlock/robosherlock/pull/215 This is the pull request I want to merge into my fork or locally. I search some questions here but that looks different, I want to merge these pull requests into my repo. This pull request is in the master branch but I have to merge in the noetic branch.

Ab Danyia
  • 69
  • 7
  • I need some clarification. We are looking at the upstream repo. You are saying you want to merge the pull request branch into your own fork of that repo? – matt Jan 01 '22 at 15:35
  • Not branch, only this pull request into my branch which is noetic but this pull request was made on the master branch. I have also a forked repo of this Robosherlock repo. Now I have to only merge this pull request only to my fork( which I will also do first locally and then make a pull request to my repo). – Ab Danyia Jan 01 '22 at 15:37
  • So you are saying you want to make a whole new pull request? Then start a branch, cherry pick `bb7efd3` onto it, and push the branch. – matt Jan 01 '22 at 15:45
  • Git fundamentally does not merge branches into branches. It merges commits into commits. Branches don't matter in Git, in other words. The commits are all that matter. (The branch names aren't useless though: they help you, and Git, *find* the commits. But that's basically it: they're just commit-finders. It's the *commits* that matter.) – torek Jan 01 '22 at 15:45
  • Yeah, I have to look in to commits, this pull request have 2 commits. – Ab Danyia Jan 01 '22 at 15:52

1 Answers1

1

Key fact: The last commit in the pull request branch is bb7efd3.

So the direct way to do this is that you would get onto the noetic branch and merge bb7efd3 into it. You will have one small merge conflict to resolve and then you're all set.


I think if I wanted to do this through a pull request I would get onto noetic, rebase the two commits of the original pull request branch onto it, call that a new branch, push my new branch, and create the pull request. Here, I'll show you:

git switch noetic
git rebase --onto noetic bb7efd3~2 bb7efd3
# ... resolve merge conflict and finish rebase ...
# ... you are now on a detached head ...
git switch -c newbranch

As you can see, the result is exactly the topology you want — a new branch off of noetic that looks like the old pull request branch:

% git log --oneline -n 3 mybranch
5242afa (HEAD -> mybranch) Fix wrong constructor name
3ef17e6 RegionFilter with markers
84cc713 (origin/noetic, noetic) changed default demo pipeline. no tf lookups anymore to avoid tf lookup errors in the tutorials

So now you can push newbranch and form a pull request in the ordinary way.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Regarding your first way, if I merge bb7efd3 into my noetic branch will the above d063211 commit will automatically merge or do I also have to do it separately? – Ab Danyia Jan 01 '22 at 15:51
  • The question makes no sense. When you say, in the ordinary way, `git merge mybranch`, you are merging _one commit_. It doesn't matter how many other commits you think are "on" the branch `mybranch`; that idea is fundamentally wrong. The history preceding the `mybranch` commit (and the history preceding current branch) is not unimportant, but only that one commit is being merged. To ask whether some other commit will merge is meaningless. – matt Jan 01 '22 at 15:59
  • So when you say "this pull request have 2 commits" you have basically misunderstood what Git is, what a commit is, and what a branch is. And what a merge is! The pull request is about _one_ commit, the last commit on that branch. Hence the form of my suggestion. – matt Jan 01 '22 at 16:01
  • Yes, I am new to this git and still learning stuff. – Ab Danyia Jan 01 '22 at 16:04
  • let me try these. Thank you! – Ab Danyia Jan 01 '22 at 16:26
  • Yeah, remember, nothing is written on tablets of jade, as long as you have pushed all your existing work. If you try something and you don't like it, you can always throw it away and clone again. – matt Jan 01 '22 at 16:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240638/discussion-between-ab-danyia-and-matt). – Ab Danyia Jan 01 '22 at 18:01
  • If you don't understand what Git is, please read my https://www.biteinteractive.com/picturing-git-conceptions-and-misconceptions/. – matt Jan 01 '22 at 18:16
  • Thank you @matt for this brief introductory blog on git. I read it and get some core concepts. Now I did resolve the merge conflict after `git rebase --onto noetic bb7efd3~2 bb7efd3` now after doing `git rebase --continue` my terminal got stuck to it. Do you know the reson? – Ab Danyia Jan 01 '22 at 21:33
  • I don't know what "my terminal got stuck to it" means. Perhaps it is waiting for your editor to submit the commit message? – matt Jan 01 '22 at 21:43
  • hi @matt, i attach a screenshot in your answer of problem – Ab Danyia Jan 01 '22 at 21:50
  • Well don't do that. You want to edit something, edit _your_ question. You leave my answer alone. Thank you. – matt Jan 01 '22 at 21:55
  • OK to it's exactly as I said. That is your editor (vim) and it is waiting for you to save the commit message and exit. See https://stackoverflow.com/questions/13239368/git-how-to-close-commit-editor – matt Jan 01 '22 at 21:56
  • Thank you @matt for your time. Now it is working – Ab Danyia Jan 01 '22 at 22:16