'How to bring origin/master to latest commit without pushing to remote? [closed]

I want to make this happen without any pushing to the remote repository.

From this: commit (HEAD -> master)

        `commit (origin/master)`

To : commit (HEAD -> master, origin/master)

git


Solution 1:[1]

git update-ref refs/remotes/origin/master <sha1_of_the_commit_you_want>

Updates the given ref (here origin/master, of its complete name refs/remotes/origin/master) to point the given commit. update-ref will only change a local ref (refs/remotes/origin/master is a local ref) and does no network call, nothing changes on the actual remote. This can work for local branches too, like master (complete name refs/heads/master).

Note that origin/master will be re-synced on your next fetch (or pull, which includes a fetch)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1