Programmatically insert current branch into command


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?


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

Answered By – LeGEC

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published