Home > database >  How to push to remote repo after rebase without all previous added commit history?
How to push to remote repo after rebase without all previous added commit history?

Time:11-24

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.

CodePudding user response:

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.

  • Related