update-bash: fix git_init_if_necessary
update-bash: fix git_init_if_necessary

* Make sure `.git` directory be deleted at any error. So we won't have a
  stale setup.
* Run `git fetch` and `git reset` when initialize git in the first time.
  Otherwise, we will get error and merging problem afterwards.

Closes Homebrew/homebrew#48509.

Signed-off-by: Xu Cheng <9a05244150b861e40c78843b801eed71bca54eac@me.com>

nandub/brew,claui/brew,toonetown/homebrew,bfontaine/brew,sjackman/homebrew,tonyg/homebrew,rwhogg/brew,jmsundar/brew,tonyg/homebrew,gregory-nisbet/brew,hanxue/linuxbrew,gregory-nisbet/brew,Homebrew/brew,claui/brew,mistydemeo/homebrew,toonetown/homebrew,EricFromCanada/brew,Homebrew/brew,reitermarkus/brew,Linuxbrew/brew,maxim-belkin/brew,ilovezfs/brew,sjackman/homebrew,gregory-nisbet/brew,Homebrew/brew,zmwangx/brew,reelsense/brew,mahori/brew,toonetown/homebrew,palxex/brew,konqui/brew,amar-laksh/brew_sudo,mahori/brew,MikeMcQuaid/brew,rwhogg/brew,EricFromCanada/brew,bfontaine/brew,AnastasiaSulyagina/brew,muellermartin/dist,reitermarkus/brew,JCount/brew,DomT4/brew,jmsundar/brew,vitorgalvao/brew,zmwangx/brew,reitermarkus/brew,vitorgalvao/brew,mahori/brew,MikeMcQuaid/brew,hanxue/linuxbrew,EricFromCanada/brew,JCount/brew,mistydemeo/homebrew,ilovezfs/brew,zmwangx/brew,palxex/brew,Linuxbrew/brew,amar-laksh/brew_sudo,Homebrew/brew,rwhogg/brew,alyssais/brew,palxex/brew,reelsense/brew,muellermartin/dist,konqui/brew,Linuxbrew/brew,DomT4/brew,hanxue/linuxbrew,AnastasiaSulyagina/brew,nandub/brew,pseudocody/brew,DomT4/brew,gordonmcshane/homebrew,JCount/brew,gordonmcshane/homebrew,aw1621107/brew,vitorgalvao/brew,mgrimes/brew,staticfloat/brew,konqui/brew,maxim-belkin/brew,MikeMcQuaid/brew,mahori/brew,pseudocody/brew,aw1621107/brew,reelsense/brew,mgrimes/brew,muellermartin/dist,gordonmcshane/homebrew,nandub/brew,nandub/brew,EricFromCanada/brew,sjackman/homebrew,maxim-belkin/brew,claui/brew,Linuxbrew/brew,vitorgalvao/brew,mistydemeo/homebrew,MikeMcQuaid/brew,AnastasiaSulyagina/brew,amar-laksh/brew_sudo,ilovezfs/brew,bfontaine/brew,mgrimes/brew,DomT4/brew,alyssais/brew,JCount/brew,alyssais/brew,staticfloat/brew,tonyg/homebrew,aw1621107/brew,jmsundar/brew,konqui/brew,staticfloat/brew,pseudocody/brew,sjackman/homebrew,claui/brew,reitermarkus/brew