0

I'm not good at git yet. I want to ask you, how the rebase with remote repo should be made.

I mean, I have main branch (remote) and I also have branch eg. my_branch (local). When PR for merging my_branch to main was open, there was few more commits added to main that causes conflicts on my_branch.

So, I always:

  • update main branch
  • checkout my_branch
  • rebase my_branch with main
  • resolve conflicts
  • pull changes
  • commit
  • push to remote main

But, it creates in the PR weird commit history and also adding these to my PR. I don't want it. I would like to rebase my_branch with main, push it to the remote repo and won't see these commits that was added to main when my PR was open for a while.

How can I change it? I know that there is a way, but I don't understand it correctly. Anyone can explain?

Thanks in advance.

Yunnane
  • 85
  • 9
  • Generally I recommend not to use `git pull`. It does two things (`git fetch` and `git merge`) and especially for beginners it is easier to do those two steps one by one. – SebDieBln Nov 23 '22 at 12:34
  • I don't see why you would pull (fetch and merge) after you resolved the conflicts. Does omitting this step already solve your issue? – SebDieBln Nov 23 '22 at 12:35
  • Ok, so I go to the main branch, run git fetch to update repository, checkout my branch. What should I do next? – Yunnane Nov 23 '22 at 13:31

1 Answers1

1

In a situation where I have a branch my_branch out of which I later want to make a pull-request I usually follow this workflow:

  • fetch
  • if the remote main has new commits:
    • rebase my local my_branch onto the remote main, resolving conflicts if they appear
  • add some commits to my_branch
  • push my_branch (using --force-with-lease if I have already pushed before)

Now my work is present in the remote and I can create a pull request out of that branch or just have it sitting there for a while as a backup.

SebDieBln
  • 3,303
  • 1
  • 7
  • 21