Set otherbranch to point at the same commit as currentbranch by running

git branch -f otherbranch currentbranch

The -f (force) option tells git branch yes, I really mean to overwrite any existing otherbranch reference with the new one.

From the documentation:

-f
--force

Reset to if exists already. Without -f git branch refuses to change an existing branch.

Answer from Colin D Bennett on Stack Overflow
Discussions

How do I overwrite one branch with another branch?
Why not... make a new branch? More on reddit.com
🌐 r/git
23
42
May 20, 2019
Switch Git branch without files checkout - Stack Overflow
Use echo "ebff34ffb665de069487... by git reset to point to a ref instead of a branch. 2012-10-18T19:03:21.73Z+00:00 ... Directly writing to the HEAD file is less dependable. What if you are in a subdir? For detached head (head pointing to SHA1 directly), try this: git update-ref HEAD refs/heads/otherbranch 2013-01-23T20:25:53.6Z+00:00 ... If you want to check out to a fresh branch from the current branch, another way to do this is to 1. git stash 2. git checkout -b otherBranch ... More on stackoverflow.com
🌐 stackoverflow.com
Ability to move branch pointer to different commit without checkout
Description It would be nice if Git Graph provided the ability to move a branch that is not checked-out to another commit. The git command is git branch -f branch-name new-tip-commit. ... Select Reset branch... More on github.com
🌐 github.com
6
April 2, 2020
What's the difference between "git reset" and "git checkout"? - Stack Overflow
You can look around, make experimental ... state without impacting any branches by switching back to a branch. ... git switch -c : a new branch will be created from that commit and it will become your current branch. git switch -c -> it is basically undoing the checkout command which brings you back to your old branch. ... git checkout will move the HEAD to another commit(could ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 ...
🌐
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 - Then checkout your branch, and either: rebase your branch onto master, or merge master into your branch. ... 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...
🌐
Graphite
graphite.com › guides › git-hard-reset-remote
Git hard reset to remote - Graphite
Hard resetting in Git, git reset --hard, is a powerful operation that can synchronize your local branch with a remote branch, discarding all local changes and making your branch identical to the remote one.
Find elsewhere
🌐
GitHub
github.com › mhutchie › vscode-git-graph › issues › 288
Ability to move branch pointer to different commit without checkout · Issue #288 · mhutchie/vscode-git-graph
April 2, 2020 - Description It would be nice if Git Graph provided the ability to move a branch that is not checked-out to another commit. The git command is git branch -f branch-name new-tip-commit. ... Select Reset branch...
Author   mhutchie
Top answer
1 of 8
235
  • git reset is specifically about updating the index, moving the HEAD.
  • git checkout is about updating the working tree (to the index or the specified tree). It will update the HEAD only if you checkout a branch (if not, you end up with a detached HEAD).
    (actually, with Git 2.23 Q3 2019, this will be git restore, not necessarily git checkout)

By comparison, since svn has no index, only a working tree, svn checkout will copy a given revision on a separate directory.
The closer equivalent for git checkout would:

  • svn update (if you are in the same branch, meaning the same SVN URL)
  • svn switch (if you checkout for instance the same branch, but from another SVN repo URL)

All those three working tree modifications (svn checkout, update, switch) have only one command in git: git checkout.
But since git has also the notion of index (that "staging area" between the repo and the working tree), you also have git reset.


Thinkeye mentions in the comments the article "Reset Demystified ".

For instance, if we have two branches, 'master' and 'develop' pointing at different commits, and we're currently on 'develop' (so HEAD points to it) and we run git reset master, 'develop' itself will now point to the same commit that 'master' does.

On the other hand, if we instead run git checkout master, 'develop' will not move, HEAD itself will. 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 to point to another branch.

On those points, though:

LarsH adds in the comments:

The first paragraph of this answer, though, is misleading: "git checkout ... will update the HEAD only if you checkout a branch (if not, you end up with a detached HEAD)".
Not true: git checkout will update the HEAD even if you checkout a commit that's not a branch (and yes, you end up with a detached HEAD, but it still got updated).

git checkout a839e8f updates HEAD to point to commit a839e8f.

De Novo concurs in the comments:

@LarsH is correct.
The second bullet has a misconception about what HEAD is in will update the HEAD only if you checkout a branch.
HEAD goes wherever you are, like a shadow.
Checking out some non-branch ref (e.g., a tag), or a commit directly, will move HEAD. Detached head doesn't mean you've detached from the HEAD, it means the head is detached from a branch ref, which you can see from, e.g., git log --pretty=format:"%d" -1.

  • Attached head states will start with (HEAD ->,
  • detached will still show (HEAD, but will not have an arrow to a branch ref.
2 of 8
76

In their simplest form, reset resets the index without touching the working tree, while checkout changes the working tree without touching the index.

Resets the index to match HEAD, working tree left alone:

git reset

Conceptually, this checks out the index into the working tree. To get it to actually do anything you would have to use -f to force it to overwrite any local changes. This is a safety feature to make sure that the "no argument" form isn't destructive:

git checkout

Once you start adding parameters it is true that there is some overlap.

checkout is usually used with a branch, tag or commit. In this case it will reset HEAD and the index to the given commit as well as performing the checkout of the index into the working tree.

Also, if you supply --hard to reset you can ask reset to overwrite the working tree as well as resetting the index.

If you current have a branch checked out out there is a crucial different between reset and checkout when you supply an alternative branch or commit. reset will change the current branch to point at the selected commit whereas checkout will leave the current branch alone but will checkout the supplied branch or commit instead.

Other forms of reset and commit involve supplying paths.

If you supply paths to reset you cannot supply --hard and reset will only change the index version of the supplied paths to the version in the supplied commit (or HEAD if you don't specify a commit).

If you supply paths to checkout, like reset it will update the index version of the supplied paths to match the supplied commit (or HEAD) but it will always checkout the index version of the supplied paths into the 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.
🌐
Towards Data Science
towardsdatascience.com › home › latest › git undo : how to rewrite git history with confidence
Git UNDO : How to Rewrite Git History with Confidence | Towards Data Science
April 22, 2026 - You can start by using git reset --soft HEAD~1. This would set main to point to the previous commit, “Commit 2.4”: Changing `main`; “Commit 3 is blurred because it’s still there, just not reachable (image by author) Peeking at the ...
🌐
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:
🌐
jwiegley
jwiegley.github.io › git-from-the-bottom-up › 3-Reset › 4-doing-a-hard-reset.html
Doing a hard reset | Git from the Bottom Up
There is also another command, checkout, which operates just like reset --hard if the index is empty. Otherwise, it forces your working tree to match the index. Now, if you do a hard reset against an earlier commit, it’s the same as first doing a soft reset and then using reset --hard to ...
🌐
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:
🌐
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 - When resetting a local Git branch to remote, you will lose the changes you made locally. This step is optional, and you may choose to do it just in case something goes wrong or you want to go back to that work again in the future. ... Your work now is saved to the branch named backup_work. 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:
🌐
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?

🌐
GitKraken
gitkraken.com › home › learn › git reset
Git Reset | Hard, Soft & Mixed | Learn Git
March 26, 2026 - Git checkout and Git reset both change where HEAD is pointing, but in the case of checkout, it leaves any other pointers in place. Git reset, on the other hand, tells Git that we want to move the pointer HEAD is referencing as well. In order to understand Git reset, you must first understand another core Git concept, which is the internal states that Git uses to manage your work.
🌐
Reddit
reddit.com › r/git › how to keep changes if i wanna checkout to another branch but i don't wanna commit them yet?
r/git on Reddit: How to keep changes if I wanna checkout to another branch but I don't wanna commit them yet?
May 30, 2022 -

Let's say I'm on branch A and I do some changes on the branch. For some reasons, I need to checkout to branch B. But the problem is I don't wanna commit them yet. I just wanna keep them without commiting them.

I already tried stashing using git add . and then git stash. But I'm not sure if I do it right because after I run git stash, it automatically removes my changes. And when I switch to another branch & then switch back to that branch, all the changes disappeared.

What should I actually do in this situation? Any advice?

Top answer
1 of 8
9
When you get back to the branch where you did git stash do git stash pop to get your changes back.
2 of 8
6
There are several approaches. Let me list them in increasing order of convenience Stash Stash is probably what the most will suggest you. The problem with stash is that it's kind of an afterthought in Git, not perfectly consistent with other Git functionalities. Temporary branch A second, trivial, option is: git checkout -b temp git add . git commit -m "WIP restart from here" Feel free to move to another branch. When you are done, you can switch back to the temporary branch. Only, remember to commit with --amend when you are done. git checkout temp echo "your work" git commit -am "My work" --amend I usually do this. But it's a bit cumbersome show and ls-tree You don't need to checkout a branch / commit to visit it. git show is already able to display all the needed information. For example, git show B:your-file.txt will display the content of your-file.txt at branch B. You can ls a dir with git ls-tree git ls-tree B:your-directory/ Most of the GUI tools allow to browse the whole filesystem without checking it out. Workdir This is probably the trick you are looking for. Starting from Git 2.5, you can actually have multiple branches checked out at the same time. This is a not-so-well-known feature, which might come in handy for your specific case. worktree allows you to create an arbitrary number of directories ("worktrees"), each checked out to an independent branch. In other words, a worktree is like an additional Git clone, sharing the same .git directory of the main clone. git worktree add ../another-branch cd ../another-branch git checkout B If you enter your another-branch, you will see that it's an ordinary Git clone, with the notable exception that the .git directory is actually a text file, containing a reference to your original clone. You can control your worktrees with git worktree list and other handy commands, whose use I'm sure you will find straightforward Edit: typo
🌐
Atlassian
atlassian.com › git › tutorials › resetting checking out and reverting
Resetting, Checking Out & Reverting | Atlassian Git Tutorial
December 16, 2025 - Internally, all the above command does is move HEAD to a different branch and update the working directory to match. Since this has the potential to overwrite local changes, Git forces you to commit or stash any changes in the working directory that will be lost during the checkout operation. Unlike git reset, git checkout doesn’t move any branches around.
🌐
Gitbybit
gitbybit.com › gitopedia › git-commands › git-reset
Gitopedia: git reset — move a branch pointer
The number after ~ tells Git how many commits back to go, so HEAD~3 means "three commits before HEAD." You can also specify the destination using a commit hash, branch, or another commit reference. Be careful when using git reset, especially with the --hard option, as it can permanently discard ...