Generic git reset to default upstream HEAD
Asked Answered
B

1

6

Is there a syntax to reset to the current branch's default upstream HEAD?

Something like:

git checkout mybranch
git reset --hard origin/mybranch

where origin/mybranch can be generic for the current branch's upstream HEAD?

Boothman answered 13/11, 2013 at 17:59 Comment(0)
E
8

The syntactic magic you want is part of a "revision specifier". These are documented in gitrevisions.

The string @{upstream} (abbreviation, @{u}), appended to a branch name, means "resolve the branch to its upstream". If you omit the branch name, git substitutes in HEAD, i.e., HEAD@{u}. This uses HEAD to find the current branch and then proceeds as if you had specified that.

So:

git reset --hard @{u}

will do the job (of course as with any git reset --hard, use this with care).

(In some shells you may have to quote the braces.)

Emancipator answered 13/11, 2013 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.