Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing duplicate commits on subsequent pull requests

So from what I understand, after I've made a pull request and it has been merged, GitHub creates a "Merge Commit" to signify this.

However, if I make another pull request down the line, even after merging the merge commit into my local fork, it shows all of the commits from previous pull requests as well.

The only way I can seem to get around this is directly after having a pull request merged, resetting my local head to the original repo's merge commit in GitKraken, and then force-pushing to my fork.

The issue is, this feels like it's a very wrong way of doing things. Is that true? And if so, how should I be going about it instead?

like image 953
Nat Karmios Avatar asked Sep 11 '25 14:09

Nat Karmios


1 Answers

Force pushing usually means something isn't quite right.

It sounds like you aren't updating your local upstream branch after you hit the merge button on GitHub.com.

Short version

git checkout master
git pull --all
git checkout -b feature-branch
git add stuff
git commit -m "cool feature"
git push origin feature-branch
<click merge on GitHub.com>
git checkout master
git pull --all -p
git branch -d feature-branch
<see refs move, your feature branch get cleaned>

If you branch again from this point, you won't see the "cool feature" commit in later PRs since your local master has it.

More Details.

After you merge, run git pull --all -p to update your local repo with all the remotes and their refs. -p will also prune merged branch refs to clean up your tab complete list.

So, the sequence usually goes:

git checkout master git pull --all -p ; This should update your local master unless it differs from upstream if you do have local changes on master, you should either push them, or through them away.

if you want to throw them away, and make your master a copy of the upstream on

git reset --hard origin/master will make the current local branch a copy of the remote ref.

like image 54
EnabrenTane Avatar answered Sep 14 '25 04:09

EnabrenTane