Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit squashed when merging upstream, how do I update my local repo

Tags:

git

merge

github

I made a few commits in a local repo, pushed those to the remote and created a Pull Request to the upstream master. Those commits were squashed when the PR was merged.

$ git commit A
$ git push origin master
$ git commit B
$ git push origin master

Create PR, squash and merge into upstream master

Then when I do ...

$ git pull upstream master

It does a merge instead of a fast forward since the commit is different. How do I update my local repo to match the upstream master history after commits have been changed/squashed upstream?

I ended up doing the following ...

$ git reset HEAD~2 --hard
$ git pull upstream master
$ git push origin master --force

To match my history, but I'm hoping there's a much cleaner way to do this.

like image 621
Erich Avatar asked Jan 20 '26 10:01

Erich


1 Answers

If you don't have any local changes you wanna save, you can just reset your local branch to match the remote.

First, get the new data from remote with

git fetch upstream

Second, after double checking that you are in your local master branch

git reset --hard upstream/master

That would reset your local branch to match the one at the remote.

like image 86
Jaakko Avatar answered Jan 22 '26 04:01

Jaakko