Search code examples
gitpull-requestgit-rebase

Problems after accept a pull request doing rebase


Having two problems with pull requests

I have a repository where there is 1 branch called main.

To implements a new feature I create a new branch from the HEAD of main running git checkout -b new-feature main. After the changes has been implemented at new-feature and push to that branch, I make the pull request to main branch.

My questions are:

  1. After the Pull Request was accepted (doing rebase from GitHub), what should I do with new-feature branch?

  2. If I dont delete new-feature branch, can I continue pushing commits on that branch?

After my Pull Request was accepted, I did the next steps:

  1. checkout to main branch
  2. do a git pull --rebase to bring the changes performed from the Pull Request
  3. Tried to push another commit to new-feature

At this point, the github repository shows the next information: 2 commits ahead of, 3 commits behind main.

Why my new-feature branch is in this state?

After this I tried to make a Pull Request from the last commit but at the moment of fill the message and send the PR, GitHub shows the next message: Can’t automatically merge. Don’t worry, you can still create the pull request.

What is this message? I commited a mistake? Is there a solution?

Thanks in advance, if more information is needed, ask me for it.

EDIT: Sorry, I forgot to mention the next:

If I push this commits: 2 commits ahead of, 3 commits behind main. I get a infinite loop and then I can push these commits infinitely

Why this happends and how I can fix this loop?


Solution

  • I didn't full get the current state you're at, but my answer may helps anyway.

    I normally delete branches after the pr is done, as with that, everything the branch was for should be done. But sounds like you want to push incremental changes to main, which you ofc can do.

    For your infinite loop: I suggest rebasing your feature branch on main and force push on the feature branch. Or the may more simple solution: delete your local feature branch and pull it again from remote. Or delete it locally and remote and create a new one from main.