trainer.push_to_hub() doesn't work
Author: nawta
Pull request: no
Labels: name: bug

### System Info

after I trained via Trainer.train(), I found I can't push my model to hub even though there is no conflict or so.
I could save my model to local by trainer.save_model("path/to/local/model").

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

`
def compute_metrics(pred):
    pred_logits = pred.predictions 
    pred_ids = np.argmax(pred_logits, axis=-1)

    pred.label_ids[pred.label_ids == -100] = processor.tokenizer.pad_token_id

    pred_str = processor.batch_decode(pred_ids)
    # we do not want to group tokens when computing the metrics
    label_str = processor.batch_decode(pred.label_ids, group_tokens=False)

    cer = cer_metric.compute(predictions=pred_str, references=label_str)

    return {"cer": cer}

from transformers import Wav2Vec2ForCTC

cer_metric = load_metric("cer", revision="master")

model = Wav2Vec2ForCTC.from_pretrained(
    "facebook/wav2vec2-base", 
    ctc_loss_reduction="mean", 
    pad_token_id=processor.tokenizer.pad_token_id,
    vocab_size=48
)

model.to('cuda')

from transformers import TrainingArguments

training_args = TrainingArguments(
  output_dir= repo_name,
  group_by_length=True,
  per_device_train_batch_size=32,
  evaluation_strategy="steps",
  num_train_epochs=30,
  fp16=True,
  gradient_checkpointing=True,
  save_steps=500,
  eval_steps=500,
  logging_steps=500,
  learning_rate=1e-4,
  weight_decay=0.005,
  warmup_steps=1000,
  save_total_limit=2,
  push_to_hub=True,
)

from transformers import Trainer

trainer = Trainer(
    model=model,
    data_collator=data_collator,
    args=training_args,
    compute_metrics=compute_metrics,
    train_dataset=rwcp_ssd_ono["train"],
    eval_dataset=rwcp_ssd_ono["eval"],
    tokenizer=processor.feature_extractor,
)

trainer.train()
trainer.push_to_hub()
`

### Expected behavior

```
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/huggingface_hub/repository.py in git_commit(self, commit_message)
    903         try:
--> 904             lfs_config = "git config lfs.customtransfer.multipart"
    905             run_subprocess(f"{lfs_config}.path huggingface-cli".split(), self.local_dir)

/opt/conda/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', 'End of training', '-v']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
/tmp/ipykernel_2655812/1405518398.py in <module>
----> 1 trainer.push_to_hub()

/opt/conda/lib/python3.7/site-packages/transformers/trainer.py in push_to_hub(self, commit_message, blocking, **kwargs)
   2675             return
   2676 
-> 2677         git_head_commit_url = self.repo.push_to_hub(commit_message=commit_message, blocking=blocking)
   2678         # push separately the model card to be independant from the rest of the model
   2679         if self.args.should_save:

/opt/conda/lib/python3.7/site-packages/huggingface_hub/repository.py in push_to_hub(self, commit_message, blocking, clean_ok)
   1191         return self.git_head_commit_url()
   1192 
-> 1193     def git_checkout(self, revision: str, create_branch_ok: Optional[bool] = False):
   1194         """
   1195         git checkout a given revision

/opt/conda/lib/python3.7/site-packages/huggingface_hub/repository.py in git_commit(self, commit_message)
    909             )
    910         except subprocess.CalledProcessError as exc:
--> 911             raise EnvironmentError(exc.stderr)
    912 
    913     def auto_track_binary_files(self, pattern: Optional[str] = ".") -> List[str]:

OSError: On branch main
Your branch is ahead of 'origin/main' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
```

Comments:
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/main/CONTRIBUTING.md) are likely to be ignored.

Facing a similar as above issue, have anyone found the solution to it?

having the same issue

having the same issue