AndreKR
AndreKR

Reputation: 33658

Reset local Git branch to remote

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

Answers (1)

Chris
Chris

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 the master branch and it’s tracking origin/master, you can say something like git merge @{u} instead of git merge origin/master if you wish.

Upvotes: 3

Related Questions