1

Is it possible to reset branch that is not currently checked out?

I want to create a cron script that will perform git svn fetch and then update all local branches tracking svn remote branches with new changes.

michael nesterenko
  • 14,222
  • 25
  • 114
  • 182
  • Remote changes are automatically updated. Local branches are not. But what's the point in having them updated, if they aren't checked out anyway – knittl Aug 03 '12 at 10:04
  • @knittl, this repository is used by gerrit. Main upstream repository is svn and I need from time to time synchronize git repository with changes from svn. That is why I need to reset a branch that is not currently checked out. – michael nesterenko Aug 03 '12 at 10:48
  • @knittl, updated question to avoid confusion. – michael nesterenko Aug 03 '12 at 10:50

1 Answers1

2

Sure, easily.

git update-ref -m "message" refs/heads/whatever new-value old-value

The message is whatever you want to appear in reflog. You can omit that.

The old-value is there to avoid race-conditions. It checks that the ref still has that value before the update, so if another script updates it while you are processing it, the operation will fail. If you don't have risk of race-conditions, you don't have to specify it.

You of course have to know what you are doing. Take care not to drop any important revisions there.

You also must not do this to the checked-out branch. It might be most useful to avoid having any branch at all checked out by doing git checkout HEAD@{}. That will make the special ref HEAD store the commit ID directly, you can update any ref and than you can come back and git checkout whatever you want.

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172