Yathi
Yathi

Reputation: 1051

Git - How to force pull from an upstream remote and ignore commits in your local and remote?

I want to pull from from an upstream branch and I want to ignore all commits made by me in my local and my remote on git. I only want the changes from the upstream remote.

I am having issues with:

git pull upstream master

And I do not want to manually merge them. I just want to ignore all my local changes and the above command to work.

I tried:

git reset --hard

But that doesn't seem to work for me. I want the changes from the upstream.

Upvotes: 27

Views: 25584

Answers (2)

Yathi
Yathi

Reputation: 1051

Another way to achieve this which I have now found is, you can remove all changes in your branch with

git checkout .

Once your branch is clean, you can checkout another branch with:

git checkout <anotherbranchname>

Now you can delete the old branch locally by running:

git branch -d <branchtoremovelocalchanges>

Now you can go to that branch again with:

git checkout <branchtoremovelocalchanges>

and now you will see everything the way it is on the server. I know this is a more roundabout way of achieving what the first answer suggests, but its another option.

Upvotes: 1

You need to specify the remote name because it is equal to origin by default

git reset --hard upstream/master

Upvotes: 54

Related Questions