Submitting multiple pull requests in a row causes commits to be added to the same PR

1.  Introduction

So, I was working on a feature branch of a forked repository and was about to push that branch in order to create a pull request out of it.

I develop my changes, test, commit, push the branch and create a PR.

2. Situation

However, while working on the fore-mentioned feature branch, I also noticed that another PR was needed. I’m working with IntelliJ, so, I at some point noticed that the git ignore file of the project didn’t include any mention to specific IDE-generated files

3. Problem

Ok, cool, so, I have to create a new PR, cuz it’s about something totally different.

So, checked out a new branch, committed the changes, pushed the branch and…

What? Why my newly pushed branch is 2 commits ahead of master? I just pushed one commit!

Side note here is that if I create a new PR based on this branch, the changes of my first PR would still be included. So, I have to somehow remove them, synchronize my gitignore-branch with master and then push the branch again, by erasing the previously logged history.

4. Solution

Oke, lemme check:

Pooooh, of course, when I checked out to a new branch, I have already pushed my first branch, so the newly created branch has on top of its HEAD the latest “local” changes. Let’s reset it back to a valid remote state. That is, just after cloning it:

I’m on the branch which has to do with the update of the .gitignore file, so I only wanna add the .gitignore file ot it and then force the push, so that I erase all the previously existing history of the tree and have a single commit displayed to my branch ( and my PR, of course):

5. Confirmation