Error when doing `push_to_hub` two times in a row
Author: thomwolf
Pull request: no

When doing `tokenizer.push_to_hub()` with the same tokenizer that was already uploaded (can happen in a notebook in particular), we have a git error:

```bash
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
~/miniconda2/envs/datasets/lib/python3.7/site-packages/huggingface_hub/repository.py in git_commit(self, commit_message)
    424                 encoding="utf-8",
--> 425                 cwd=self.local_dir,
    426             )

~/miniconda2/envs/datasets/lib/python3.7/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    511             raise CalledProcessError(retcode, process.args,
--> 512                                      output=stdout, stderr=stderr)
    513     return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '['git', 'commit', '-m', 'add tokenizer']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-55-99316ec239b8> in <module>
----> 1 new_tokenizer.push_to_hub("thomwolf/codeparrot-small-vocabulary")
      2 
      3 reloaded_tokenizer_small = AutoTokenizer.from_pretrained("thomwolf/codeparrot-small-vocabulary")

~/miniconda2/envs/datasets/lib/python3.7/site-packages/transformers/file_utils.py in push_to_hub(self, repo_path_or_name, repo_url, use_temp_dir, commit_message, organization, private, use_auth_token)
   2029         self.save_pretrained(repo_path_or_name)
   2030         # Commit and push!
-> 2031         url = self._push_to_hub(repo, commit_message=commit_message)
   2032 
   2033         # Clean up! Clean up! Everybody everywhere!

~/miniconda2/envs/datasets/lib/python3.7/site-packages/transformers/file_utils.py in _push_to_hub(cls, repo, commit_message)
   2109                 commit_message = "add model"
   2110 
-> 2111         return repo.push_to_hub(commit_message=commit_message)

~/miniconda2/envs/datasets/lib/python3.7/site-packages/huggingface_hub/repository.py in push_to_hub(self, commit_message)
    459         """
    460         self.git_add()
--> 461         self.git_commit(commit_message)
    462         return self.git_push()
    463 

~/miniconda2/envs/datasets/lib/python3.7/site-packages/huggingface_hub/repository.py in git_commit(self, commit_message)
    429                 raise EnvironmentError(exc.stderr)
    430             else:
--> 431                 raise EnvironmentError(exc.stdout)
    432 
    433     def git_push(self) -> str:

OSError: Sur la branche main
Votre branche est à jour avec 'origin/main'.

rien à valider, la copie de travail est propre
```

Comments:
Maybe this should fall gracefully?

Yes I agree

(it should only catch the error when calling `.push_to_hub()`, I think calling `.git_commit()` on an empty change set should still pop an error)

Adding the `--allow_empty` option to the `git_commit()` method as a boolean flag would be clean here. This way there's no need to try/except in downstream libraries, only to specify that having empty commits is okay then.

Proposal in https://github.com/huggingface/huggingface_hub/pull/220, that will need to be ported to `transformers`. Will PR this to `transformers` if this change looks good to you.

> When doing `tokenizer.push_to_hub()` with the same tokenizer that was already uploaded (can happen in a notebook in particular), we have a git error:
> 
> ```shell
> ---------------------------------------------------------------------------
> CalledProcessError                        Traceback (most recent call last)
> ~/miniconda2/envs/datasets/lib/python3.7/site-packages/huggingface_hub/repository.py in git_commit(self, commit_message)
>     424                 encoding="utf-8",
> --> 425                 cwd=self.local_dir,
>     426             )
> 
> ~/miniconda2/envs/datasets/lib/python3.7/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
>     511             raise CalledProcessError(retcode, process.args,
> --> 512                                      output=stdout, stderr=stderr)
>     513     return CompletedProcess(process.args, retcode, stdout, stderr)
> 
> CalledProcessError: Command '['git', 'commit', '-m', 'add tokenizer']' returned non-zero exit status 1.
> 
> During handling of the above exception, another exception occurred:
> 
> OSError                                   Traceback (most recent call last)
> <ipython-input-55-99316ec239b8> in <module>
> ----> 1 new_tokenizer.push_to_hub("thomwolf/codeparrot-small-vocabulary")
>       2 
>       3 reloaded_tokenizer_small = AutoTokenizer.from_pretrained("thomwolf/codeparrot-small-vocabulary")
> 
> ~/miniconda2/envs/datasets/lib/python3.7/site-packages/transformers/file_utils.py in push_to_hub(self, repo_path_or_name, repo_url, use_temp_dir, commit_message, organization, private, use_auth_token)
>    2029         self.save_pretrained(repo_path_or_name)
>    2030         # Commit and push!
> -> 2031         url = self._push_to_hub(repo, commit_message=commit_message)
>    2032 
>    2033         # Clean up! Clean up! Everybody everywhere!
> 
> ~/miniconda2/envs/datasets/lib/python3.7/site-packages/transformers/file_utils.py in _push_to_hub(cls, repo, commit_message)
>    2109                 commit_message = "add model"
>    2110 
> -> 2111         return repo.push_to_hub(commit_message=commit_message)
> 
> ~/miniconda2/envs/datasets/lib/python3.7/site-packages/huggingface_hub/repository.py in push_to_hub(self, commit_message)
>     459         """
>     460         self.git_add()
> --> 461         self.git_commit(commit_message)
>     462         return self.git_push()
>     463 
> 
> ~/miniconda2/envs/datasets/lib/python3.7/site-packages/huggingface_hub/repository.py in git_commit(self, commit_message)
>     429                 raise EnvironmentError(exc.stderr)
>     430             else:
> --> 431                 raise EnvironmentError(exc.stdout)
>     432 
>     433     def git_push(self) -> str:
> 
> OSError: Sur la branche main
> Votre branche est à jour avec 'origin/main'.
> 
> rien à valider, la copie de travail est propre
> ```

Not sure if this is the same, but I have a similar problem when using `model.push_to_hub`:

```
from transformers import AutoModel

model = AutoModel.from_pretrained('/path/to/my/fine-tuned/model/on/my/local/machine')

model.push_to_hub("my-username/my-model-name")
```

And this is the error I get:

```
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-84aee0bf13c0> in <module>()
      4 model = AutoModel.from_pretrained(model_path)
      5 
----> 6 model.push_to_hub("my-username/my-model-name")

2 frames
/usr/local/lib/python3.7/dist-packages/huggingface_hub/repository.py in __init__(self, local_dir, clone_from, use_auth_token, git_user, git_email)
    102                 )
    103                 raise ValueError(
--> 104                     "If not specifying `clone_from`, you need to pass Repository a valid git clone."
    105                 )
    106 

ValueError: If not specifying `clone_from`, you need to pass Repository a valid git clone.
```

P.S. I'm running this inside Colab and I have already logged in.

Please open a new issue when you encounter a bug that is different. Here the problem is that you are not passing a valid name, it should just be `model.push_to_hub("my-model-name")` (happy to discuss more on another issue if you still have problems).

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.