user1365697 user1365697 - 28 days ago 17
Git Question

Does reset could work against remote branch?

I saw that the command

git reset --hard origin/master


is working via the remote tracking branch.

Is it possible to do reset against the remote branch and not the remote tracking branch?

Answer

Warning: these commands have the power to change history.

Use them only if you understand and accept the risk.

The command git reset --hard origin/master wouldn't have an effect on a remote branch if it were applicable; effectively, what you're telling your local branch to do is to move HEAD to the same commit as reflected in origin/master as your repository knows it. This will not touch your remote branch.

If git fetch wasn't run prior, you do run the risk of overwriting your local repository with an older variant of your remote repository, which is entirely fixable with git fetch && git reset --hard origin/master.

If you wanted to reset commits against your remote repository, you would have to first apply them to your local repository, then force-push them via git push -f.

Note that these kinds of changes that you do with respect to Git are done to your local repository first; if you want to publish them to your remote repository, you have to invoke different commands.