Github pull requests showing more and more old merges

Viewed 1585

I'm actually quite experienced with git but this weirdness is confusing me.

We have a protected master branch. Each time I want to add code, I'll pull the latest code from master, then make a new local branch based on that. Commit my changes, push them up in my new branch, then make a PR back to master.

Standard stuff.

One thing I've noticed in this particular repo is that I'm getting more and more "changes" in my branch, and they're simply merges from days ago.

For example, my latest PR has:

Merge branch 'master' of github.com:xxxx/xxxx into master

8 total times, the oldest of which is 11 days old. Before all these merges is a single old commit of mine that was already merged into master, and I see this commit every single time I make a PR. At the very end is the single commit that I added in my branch.

When looking at files changed, only the files I actually changed in my branch are included, so it's totally harmless to merge my PRs in. It's just weird and annoying.

Also locally, if I delete a branch that was already merged, I get the warning "contains commits that weren't merged into master" even though, in reality, it does not.

Each time I make a new PR, that old commit is the first thing in the log, so I wonder if there's something screwed up about it.

Any ideas? About to just nuke my repo and re-clone.

1 Answers

It looks like you are branching off of master and then not updating your branch with the new updates from master. You can get the new commits in your branch and sync up the history with a rebase

I'd recommend the following process which is easy to follow:

  • git checkout master
  • git pull
  • git checkout [feature branch]
  • git rebase origin/master -i
  • git push origin [feature-branch] --force

In the rebase step you can pick all your commits or you can squash them using the s or squash option next to your commits instead of the default pick that appears next to your commits when the text editor opens for your interactive rebase.

After that the history of your master branch should be synced up with the history of your feature branch and only your commit will show up (I recommend squashing all those merge commits- if you follow this rebase workflow you wouldn't even need to do any merges, you can just do rebases- which doesn't add their own commits).

Cheers!

Related