Branches are merely pointers to commits. If you want to set one branch to point to the same commit as some other branch, use git reset. # Make sure your working tree is in a clean state git status # Check out the branch you want to change, e.g. some-branch git checkout some-branch # Reset that branch to some other branch/commit, e.g. target-branch git reset --hard target-branch The command git reset makes Git move the currently checked out branch to the specified commit. The option --hard makes Git set the index as well as the working tree to match that commit. For more information, check out man git-reset. Answer from alfunx on reddit.com
🌐
Reddit
reddit.com › r/git › how do i overwrite one branch with another branch?
r/git on Reddit: How do I overwrite one branch with another branch?
May 20, 2019 - Different one. I want the master branch to overwrite mine ... git reset --hard master will change your currently selected branch to exactly match master. There are other commands for if you haven't checked out the branch you want to change but ...
Discussions

'Reset any branch to here' feature
Hey, I've been wondering if anyone would be interested in such a feature I use it for over a year now in custom builds and still like it :) Most common scenario is as shown in the screenshot. Y... More on github.com
🌐 github.com
28
July 16, 2015
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 do I reset a git branch to a given previous commit and fix the detached HEAD? - Unix & Linux Stack Exchange
I needed to reset my branch to an earlier working state (commit) so I did: git reset --hard c70e611 Now I see HEAD detached at c70e611 nothing to commit, working directory clean How to fix / More on unix.stackexchange.com
🌐 unix.stackexchange.com
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
🌐
Git
git-scm.com › docs › git-reset
Git - git-reset Documentation
Suppose you are working on something and you commit it, and then you continue working a bit more, but now you think that what you have in your working tree should be in another branch that has nothing to do with what you committed previously. You can start a new branch and reset it while keeping the changes in your working tree.
🌐
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 - 1. Make sure you are on the branch you want to reset: ... 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.
🌐
GitHub
github.com › gitextensions › gitextensions › issues › 2876
'Reset any branch to here' feature · Issue #2876 · gitextensions/gitextensions
July 16, 2015 - You switched accounts on another tab or window. Reload to refresh your session. ... There was an error while loading. Please reload this page. ... There was an error while loading. Please reload this page. ... Hey, I've been wondering if anyone would be interested in such a feature I use it for over a year now in custom builds and still like it :) Most common scenario is as shown in the screenshot. You rebase your Feature branch on top of lets say master and want to push to master just the first two commits.
Author   gitextensions
🌐
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.
🌐
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:
Find elsewhere
🌐
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.
🌐
GitLab
forum.gitlab.com › how to use gitlab
Reset feature branch to master - How to Use GitLab - GitLab Forum
September 22, 2022 - 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 th…
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.

🌐
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 ...
🌐
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 - You may have done some experimental changes which just don't fit in, or you resolve a merge conflict and end up with a messy state. For such situations, the command git reset --hard could be a savior.
🌐
Medium
devdiaryacademy.medium.com › git-rollback-resetting-a-branch-to-a-specific-commit-a-case-study-19daf94c2c78
Git Rollback: Resetting a Branch to a Specific Commit — A Case Study | by Developer Diary | Medium
February 10, 2026 - Replace <commit_id> with the actual commit ID you identified in Step 1. The git reset --hard command will reset your local "development" branch to the specified commit, discarding all commits made after it.
🌐
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...
🌐
Microsoft Learn
learn.microsoft.com › en-us › visualstudio › version-control › git-manage-repository
Manage Git repos in Visual Studio | Microsoft Learn
Replace the example ID with the ID of a real commit in your branch. ... The --hard part of the command tells Git to reset the files to the state of the previous commit and discard any staged changes.
🌐
Medium
medium.com › @vishalbarvaliya › resetting-your-git-branch-to-a-previous-commit-a-complete-guide-96cc314a172e
Resetting Your Git Branch to a Previous Commit: A Complete Guide | by Vishal Barvaliya | Medium
September 8, 2024 - Your branch has accumulated multiple unnecessary commits and you want to clean it up. You’re dealing with a merge conflict and need to revert to a clean state. The `git reset --hard` command is the most direct and forceful way to reset your branch.
🌐
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.
🌐
Coderwall
coderwall.com › p › hrcb_q › restarting-a-git-branch
Restarting a Git Branch (Example)
February 25, 2016 - # assuming current branch is master and working directory is clean git branch genius-shower-idea git reset --hard origin/master · The example above works with branches other than master too — if you accidentally made commits on great-train-idea ...
🌐
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: