Say I want to run the command:
git reset --hard origin/abc
where abc
is my current branch. How can I programmatically insert the current branch into the command instead of having to run git branch --show
, copying the result, and pasting into the reset
command?
CodePudding user response:
git reset --hard origin/$(git branch --show-current)
is the answer thanks to @accdias
CodePudding user response:
You can target the upstream of any branch with <branch>@{u}
, and the upstream of your current branch with @{u}
(more details than you want to in git help gitrevisions
)
So you can reset to your upstream with :
git reset --hard @{u} # if on Windows: quote "@{u}" on Powershell and cmd.exe