Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 7
    you don't need --hard
    – ahnbizcad
    Commented Feb 5, 2020 at 3:56
  • 9
    git branch -f is useful. It's nice that I can change the branch without checking it out first.
    – remcycles
    Commented Aug 2, 2021 at 2:42
  • 2
    git branch -f <branch> <starting-point> by default sets <branch> to point at <starting-point> and if <starting-point> is also a branch, it sets remote tracking branch to <branch> to branch <starting-point>. To avoid adjustment of remote tracking branch, use extra option --no-track: git branch --no-track -f <branch> <starting-point>
    – czerny
    Commented Apr 11, 2022 at 17:27
  • 1
    I have to look this up about once a month. Really unintuitive command.
    – Dominik
    Commented Apr 21, 2023 at 9:59
  • I noticed the note about it throwing away uncommitted changes after I doing it :( Why not just give a reset command that doesn't do that, it isn't part of the question
    – rakslice
    Commented Jun 24 at 21:12