If you haven't pushed to origin yet, you can reset your branch to the upstream branch with:

git checkout mybranch
git reset --hard origin/mybranch

(Make sure that you reference your latest commit in a separate branch, like you mention in your question)

Note that just after the reset, mybranch@{1} refers to the old commit, before reset.

But if you had already pushed, see "Create git branch, and revert original to upstream state" for other options.


With Git 2.23 (August 2019), that would be one command: git switch.
Namely: git switch -C mybranch origin/mybranch

Example

C:\Users\vonc\git\git>git switch -C master origin/master
Reset branch 'master'
Branch 'master' set up to track remote branch 'master' from 'origin'.
Your branch is up to date with 'origin/master'.

That restores the index and working tree, like a git reset --hard would.


As commented by Brad Herman, a reset --hard would remove any new file or reset modified file to HEAD.

Actually, to be sure you start from a "clean slate", a git clean -f -d after the reset would ensure a working tree exactly identical to the branch you just reset to.


This blog post suggests those aliases (for master branch only, but you can adapt/extend those):

[alias]
   resetorigin = !git fetch origin && git reset --hard origin/master && git clean -f -d
   resetupstream = !git fetch upstream && git reset --hard upstream/master && git clean -f -d

Then you can type:

git resetupstream

or

git resetorigin
Answer from VonC on Stack Overflow
Top answer
1 of 5
1438

If you haven't pushed to origin yet, you can reset your branch to the upstream branch with:

git checkout mybranch
git reset --hard origin/mybranch

(Make sure that you reference your latest commit in a separate branch, like you mention in your question)

Note that just after the reset, mybranch@{1} refers to the old commit, before reset.

But if you had already pushed, see "Create git branch, and revert original to upstream state" for other options.


With Git 2.23 (August 2019), that would be one command: git switch.
Namely: git switch -C mybranch origin/mybranch

Example

C:\Users\vonc\git\git>git switch -C master origin/master
Reset branch 'master'
Branch 'master' set up to track remote branch 'master' from 'origin'.
Your branch is up to date with 'origin/master'.

That restores the index and working tree, like a git reset --hard would.


As commented by Brad Herman, a reset --hard would remove any new file or reset modified file to HEAD.

Actually, to be sure you start from a "clean slate", a git clean -f -d after the reset would ensure a working tree exactly identical to the branch you just reset to.


This blog post suggests those aliases (for master branch only, but you can adapt/extend those):

[alias]
   resetorigin = !git fetch origin && git reset --hard origin/master && git clean -f -d
   resetupstream = !git fetch upstream && git reset --hard upstream/master && git clean -f -d

Then you can type:

git resetupstream

or

git resetorigin
2 of 5
157

There is a slightly easier way to do this:

git reset --hard @{u}

@{u} is a shortcut for whatever your tracking branch is, so if you're on master and that tracks origin/master, @{u} points to origin/master.

The advantage of using this is that you don't have to remember (or type out) the full name of your tracking branch. You can also make an alias:

git-reset-origin="git reset --hard @{u}"

which will work regardless of the branch you're currently on.

🌐
Graphite
graphite.com › guides › git-hard-reset-remote
Git hard reset to remote
To perform a hard reset to a remote branch, you'll typically follow these steps in your terminal: Fetch the latest changes from the remote repository: ... This command updates your remote-tracking branches, the pointers that connect a local copy of a branch to its remote counterpoint, under refs/remotes/origin/. git fetch will fetch all of the changes that you do not have yet from the remote repository without merging those changes into your local branch.
Discussions

[Git] How to 'git reset' a remote branch?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
13
5
February 12, 2024
Reset feature branch to master
I usually do “git reset --hard master” when my feature branch is checked out. That work, but then I’m unable to push it to gitlab origin, because it tell me that there is a a pending pull… and when I pull on it, it kinda cancel the “reset --hard”… so, how can I do a reset to master ... More on forum.gitlab.com
🌐 forum.gitlab.com
1
0
September 22, 2022
How to move back to origin/master from master heads
Sorry, I'm quite confused about where you are and what you want. Here's what you said: I have resetted a merge branch from origin/master and my best guess at what you mean: you were in branch fix_branch, and you did git reset --hard origin/master . Is that right? If it is and you want to get back where you were, you can (from fix_branch) git reset --hard . For instance, you might want to git reset --hard c4e614d to move the branch back to "29th first try", or you could go to 40eb210 instead to go to "28th first try". More on reddit.com
🌐 r/git
7
1
May 4, 2021
Reset branch to remote/upstream
yes, just make another branch to reference that commit, so ``` git checkout dev git branch mydirt git reset --hard upstream/dev git push --force[-with-lease] origin ``` Then you can use the mydirt-branch to rebase or cherry-pick or merge your changes later or whatever. In this situation, I try to never directly make commits to the "official" branches from upstream, so they are always clean and ready to pull/push; I only commit to my own branches. edit: alternatively you could also just rename the current local dev branch (git branch -m dev mydirt) and then re-create it again. Same result, since branches are really really easy to manipulate in Git, but most people (myself included) find the above way with reset conceptually easier to grasp. More on reddit.com
🌐 r/git
1
4
May 6, 2023
🌐
Git
git-scm.com › docs › git-reset
Git - git-reset Documentation
After inspecting the result of the merge, you may find that the change in the other branch is unsatisfactory. Running git reset --hard ORIG_HEAD will let you go back to where you were, but it will discard your local changes, which you do not want.
🌐
Reddit
reddit.com › r/learnprogramming › [git] how to 'git reset' a remote branch?
r/learnprogramming on Reddit: [Git] How to 'git reset' a remote branch?
February 12, 2024 -

Say I have a local branch and I make change A, then push it so both the local and remote has change A. I then realize I don't want change A as there was an error in it. I can use git reset to reset my local branch to the commit before change A, but then if I do that and try to push, it doesn't work. This makes sense because technically the local branch is behind the remote branch. And a solution to this is to just make a "revert change A" commit, but I don't even want my commit history to show these two commits since they cancel each other out

Is there a way to do "git reset" a remote branch?

🌐
freeCodeCamp
freecodecamp.org › news › git-reset-origin-how-to-reset-a-local-branch-to-remote-tracking-branch
Git Reset Origin – How to Reset a Local Branch to Remote Tracking Branch
June 22, 2022 - Typically, there will be a local remote-tracking branch with the same name as the remote one that you want to reset to, such as main. Use the following command to checkout the local remote main branch: ... If you are using a different name for this branch, replace main with the name you are using. To fetch the remote repository, and the latest state and version of the code in the remote repository, enter the following command: ... origin is an alias created by Git and specifies the remote URL of the remote repository.
🌐
Sentry
sentry.io › sentry answers › git › reset a local branch to remote state in git
Reset a local branch to remote state in Git | Sentry
How do I reset the state of a branch ... this. First, download all remote branches with git fetch: git fetch origin # <-- name of remote, change if not origin...
Find elsewhere
🌐
Educative
educative.io › answers › how-to-reset-a-git-branch-to-a-remote-repository
How to reset a Git branch to a remote repository
A Git branch can be reset to exactly match the remote branch with the following commands: Save the state of your current branch in another branch, named my-backup,in case something goes wrong: ... This example assumes that the remote repo’s name is “origin” and that the branch named “master”, ​in the remote repo, matches the currently checked-out branch in your local repo.
🌐
GitLab
forum.gitlab.com › how to use gitlab
Reset feature branch to master - How to Use GitLab - GitLab Forum
September 22, 2022 - I usually do “git reset --hard master” when my feature branch is checked out. That work, but then I’m unable to push it to gitlab origin, because it tell me that there is a a pending pull… and when I pull on it, it kinda cancel the “reset ...
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-reset-a-git-branch-to-a-remote-repository
How to Reset a Git Branch to a Remote Repository? - GeeksforGeeks
May 22, 2024 - Replace branch-name with the name of the branch you want to reset. For example, if you want to reset the main branch, you would use: ... If your branch is protected and you need to force push the changes to the remote repository, use the --force ...
🌐
Appsmith
community.appsmith.com › solution › recovering-and-resetting-git-branch-safely
Recovering and Resetting a Git Branch Safely | Appsmith Community Portal
January 31, 2025 - git checkout -b test/recovery # Create a local recovery branch for the broken branch state · The test/recovery branch now serves as a backup of the broken branch in its original state. Switch back to the original branch and perform the reset.
🌐
Mike Street
mikestreety.co.uk › blog › reset-a-git-repository-back-to-origin
Reset a git repository back to origin - Mike Street - Lead Developer and CTO
February 22, 2023 - I recently had to help a colleague ... local repository nice and clean and back to it's original state. ... Replace main with your primary branch name below....
🌐
RunCloud
runcloud.io › blog › git-reset-to-revert-previous-commit
How to Use Git Reset To Revert To Previous Commit
November 6, 2025 - If you’ve already pushed those commits to a remote, you’ll need to force-push to update the remote branch: git push --force origin <branch-name> Use this with care, as it rewrites history for anyone else working on the same branch.
🌐
Git
git-scm.com › docs › git-worktree
Git - git-worktree Documentation
This new worktree is called a "linked worktree" as opposed to the "main worktree" prepared by git-init[1] or git-clone[1]. A repository has one main worktree (if it’s not a bare repository) and zero or more linked worktrees. When you are done with a linked worktree, remove it with git worktree remove. In its simplest form, git worktree add <path> automatically creates a new branch whose name is the final component of <path>, which is convenient if you plan to work on a new topic.
🌐
Rewind
rewind.com › home › blog › data recovery
How to Restore a Deleted Branch or Commit with Git Reflog
August 30, 2024 - Restoring deleted branches or commits is easy with the git 'reflog' command. Learn how to use git reflog to restore branches and commits.
🌐
Git
git-scm.com › cheat-sheet
Git Cheat Sheet
a remote branch · origin/main · current commit · HEAD · 3 commits ago · HEAD^^^ or HEAD~3 · git restore <file> OR git checkout <file> git restore --staged --worktree <file> OR git checkout HEAD <file> git reset --hard · git clean · git stash · git reset HEAD^ git rebase -i HEAD~6 · ...
🌐
30 Seconds of Code
30secondsofcode.org › home › git › repository › reset master to match remote
Git - Reset your local master branch to match remote - 30 seconds of code
March 31, 2024 - # Syntax # git fetch origin # git checkout master # git reset --hard origin/master git fetch origin git checkout master git reset --hard origin/master # Local `master` branch is now up to date with remote `master`
🌐
StudyRaid
app.studyraid.com › en › read › 15067 › 521585 › using-git-reset-hard-originbranch-name
Understand using git reset --hard origin/branch-name
This ensures you have the most recent version of the remote branch. Reset to the remote branch: git reset --hard origin/main (replace main with your branch name) moves your local branch pointer to match the remote branch (origin/main).
🌐
DEV Community
dev.to › cicube › how-to-reset-your-local-git-branch-5273
How to Reset Your Local Git Branch - DEV Community
November 7, 2024 - Once you've fetched the latest ... the git reset command with the --hard option. This has the implications of losing any uncommitted changes. Understand that this overwrites your local branch to the state of your remote branch completely.
🌐
Christian Engvall
christianengvall.se › git-reset-origin-master-to-commit
Git reset origin to commit | Christian Engvall
April 11, 2018 - Then use git reset –hard <commit-hash> to set the current branch HEAD to the commit you want. git reset --hard cedc856 git push --force origin master