Reputation: 33658
Is there a single command that (after git fetch
) resets the working copy to the state the remote branch is in?
For example, I have branch foo
checked out and it is tracking origin/foo
. I make some commits and local changes. Now I want to discard all those commits and changes and reset the local file set to origin/foo
. So I run git fetch
and then?
The closest I got is
git reset --hard origin/`git rev-parse --abbrev-ref HEAD`
but that is almost impossible to remember and only works in shells that support backticks.
Upvotes: 1
Views: 1087
Reputation: 136880
I think git reset --hard @{u}
will do what you want:
When you have a tracking branch set up, you can reference its upstream branch with the
@{upstream}
or@{u}
shorthand. So if you’re on themaster
branch and it’s trackingorigin/master
, you can say something likegit merge @{u}
instead ofgit merge origin/master
if you wish.
Upvotes: 3