If you want the two branches to be the same then

// from Develop and assuming your master is up to date with origin/master
git reset --hard master
Answer from Tim Jarvis on Stack Overflow
🌐
Medium
medium.com › @elton-martins › to-reset-a-git-branch-to-match-the-master-main-branch-6692c28a36fc
To reset a Git branch to match the master/main branch | by Elton Martins | Medium
March 15, 2024 - This git reset - -hard command will discard all local changes in your branch and set the branch to the same commit as the remote master branch.
Discussions

Reset feature branch to master
Hello, I would like to reset my 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 ... More on forum.gitlab.com
🌐 forum.gitlab.com
1
0
September 22, 2022
How to reset your main branch to a recently known working version
Here is a quick guide on how to reset your repository, main branch and live website to a previously proven working version without loosing changes since then. First the CLI stuff: cd your-website git checkout main git checkout -b lastworking hashoflastworkingversion git branch -m nonworkingchanges ... More on discourse.gohugo.io
🌐 discourse.gohugo.io
1
3
October 11, 2020
How do I reset a git branch to a given previous commit and fix the detached HEAD? - Unix & Linux Stack Exchange
How to fix / understand / get around ... in (not master). ... HEAD is where your workspace is currently in the tree of git commits; detached means that it doesn't correspond to a branch. To fix this, you should create a new branch with git checkout -b branch (replacing branch with the name you want to give your new branch). If you want to drop the commits following the one you reset to, you can ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
I made a bunch of changes on the master branch of a repo with two other team members. The changes ended up being completely scratched. How do I revert back to the original master code without hitting control-z a million times?
The direct answer is git reset --hard. That will completely reset your working directory to the latest commit on your current branch. However, that completely wipes your changes, so you should only really use that if you're 200% sure that the code will never be used. I feel like it's also pretty easy to use it and realise that you had changes in some other file which you might have wanted to keep. One safer option would be to switch to a new branch (traditionally git checkout -b BRANCH_NAME, although there's also a newer git switch command), commit your code on that branch, then return to the master branch. Edit: Oh, if you only want to selectively reset one file, then there's git checkout HEAD -- FILENAME. checkout is definitely one of the more confusing commands... http://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified makes for some good reading imo. More on reddit.com
🌐 r/git
4
0
April 7, 2022
🌐
Quora
quora.com › How-do-you-reset-a-broken-Git-branch-to-master
How to reset a broken Git branch to master - Quora
Answer: Define “broken”? If you just want to throw away all the work you can simply run “git reset --hard master” and it’s already done. If “broken” means that git repository is totally messed up and “git fsck” reports errors, it’s probably better to clone the whole repository ...
🌐
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 ...
🌐
Git
git-scm.com › docs › git-reset
Git - git-reset Documentation
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. git reset --merge keeps your local changes. ... Suppose you are interrupted by an urgent fix request while you are in the middle of a large change.
Find elsewhere
🌐
Graphite
graphite.com › guides › git-hard-reset-remote
Git hard reset to remote
If you choose to stash these changes you can then move them back to the local working directory with the command git stash pop, this pops the most recent stash off of the stash stack and merges them with your local state. ... Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite. ... Reset and push to a specific commit: If you need to reset your branch to a specific commit on the remote and push that change:
🌐
HUGO
discourse.gohugo.io › tips & tricks
How to reset your main branch to a recently known working version - tips & tricks - HUGO
October 11, 2020 - Here is a quick guide on how to reset your repository, main branch and live website to a previously proven working version without loosing changes since then. First the CLI stuff: cd your-website git checkout main git checkout -b lastworking hashoflastworkingversion git branch -m nonworkingchanges git checkout lastworking git branch -m main git push origin --force Step 1: go to your website folder Step 2: check out the main/master branch (that’s the branch with the last changes that are not...
🌐
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 - Usually, Git automatically assumes the remote repository’s name is origin. If you have a different remote name, replace origin with the name you are using. Now, reset the local main branch to the remote repository using the following command:
🌐
Git
git-scm.com › book › ms › v2 › Git-Tools-Reset-Demystified
Git - Reset Demystified
If we instead run git checkout master, develop does not move, HEAD itself does. HEAD will now point to master. So, in both cases we’re moving HEAD to point to commit A, but how we do so is very different. reset will move the branch HEAD points to, checkout moves HEAD itself.
🌐
W3Schools
w3schools.com › git › git_reset.asp
Git Reset
The first seven characters of the commit hash - this is what we need to refer to in our reset command. ... git log --oneline e56ba1f (HEAD -> master) Revert "Just a regular update, definitely no accidents here..." 52418f7 Just a regular update, definitely no accidents here... 9a9add8 (origin/master) Added .gitignore 81912ba Corrected spelling error 3fdaa5b Merge pull request #1 from w3schools-test/update-readme 836e5bf (origin/update-readme, update-readme) Updated readme for GitHub Branches daf4f7c (origin/html-skeleton, html-skeleton) Updated index.html with basic meta facaeae (gh-page/master) Merge branch 'master' of https://github.com/w3schools-test/hello-world e7de78f Updated index.html.
Top answer
1 of 2
7

HEAD is where your workspace is currently in the tree of git commits; detached means that it doesn't correspond to a branch. To fix this, you should create a new branch with git checkout -b branch (replacing branch with the name you want to give your new branch).

If you want to drop the commits following the one you reset to, you can delete the master branch and re-create it:

git branch -D master
git checkout -b master

If you're working on a repository which is pushed elsewhere you'll need to do more work to fix things up, possibly forcing a push (and telling every one else to re-clone their workspace). If you have shared state, you should really create a revert commit; take a look at git revert (starting from master and reverting all the commits starting with the one following c70e611).

2 of 2
3

HEAD detached at c70e611

This is because when you did the git reset --hard, you were not on any branch at that time. You had a detached HEAD, and that detached head got moved with the git reset --hard command, along with a rewrite of your working tree to that state.

If you want some branch foo to be c70611, then:

git checkout foo
git reset --hard c70611

If this is considered to be a good state to push to foo's upstream then just git push <remote-name> foo.

There is a more direct way to force foo to c70611 without checking it out to be the current branch. Namely, you can rewrite what foo points to using the git update-ref command.

Before doing any of the above, I would pause and try to see how I had ended up in a detached state without noticing. Perhaps it was an unfinished rebase or whatever. Step one is to review the last few entries in the git reflog to help jog your memory.

🌐
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
There are two commands you can use to achieve this. First, download all remote branches with git fetch: git fetch origin # <-- name of remote, change if not origin · Second, use git reset to sync the local branch with the remote branch:
🌐
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`
🌐
Medium
danielkirwan.medium.com › git-branches-merging-and-reverting-vs-resetting-94a73451fcb0
Git — Branches, merging and reverting vs resetting | by Daniel Kirwan | Medium
March 19, 2021 - Now, we need to switch to the new branch so that we can make changes to our project without the changes affecting the master branch. Open up your Unity project, go back to the terminal and then type: ... if you named your branch something different then swap devbranch for that name. Switch is a new command that Git is testing in place of ‘checkout’ for swapping branches.
🌐
Chocksaway
chocksaway.com › git › 2015 › 05 › 28 › reset-your-git-repository-master-branch.html
Reset your git repository master branch | chocksaway.com
May 28, 2015 - > > $ **git fetch origin && git reset --hard origin/master && git clean -f -d** > > > > There are two "-" before hard. > > > > $ git status > > > > On branch master > > > > Your branch is up-to-date with 'origin/master'. > > > > nothing to commit, working directory clean > >
🌐
Heaths
heaths.dev › tips › 2020 › 09 › 24 › getting-back-to-good-state-in-git.html
Getting back to a good state in Git | Heath Stewart’s Blog
September 24, 2020 - Note, however, that if you have ... be lost (git reflog may help restore them, but that’s another topic). Check out the option1 branch we created earlier that is in the bad state: ... Reset to the previous HEAD for your topic branch. Because you just merged your trunk e.g. master into your ...
🌐
Atlassian
atlassian.com › git › tutorials › resetting checking out and reverting
Resetting, Checking Out & Reverting | Atlassian Git Tutorial
December 16, 2025 - That’s what we’ll be exploring in this section. Note that git revert has no file-level counterpart. On the commit-level, resetting is a way to move the tip of a branch to a different commit.
🌐
GitKraken
gitkraken.com › home › learn › git reset
Git Reset | Hard, Soft & Mixed | Learn Git
March 26, 2026 - The first of the three modes you can use with Git reset is --soft for the Git reset soft command. This option moves HEAD back to the specified commit, undoes all the changes made between where HEAD was pointing and the specified commit, and ...