# Managing local and online repositories

The `Repository` class is a helper class that wraps `git` and `git-lfs` commands. It provides tooling adapted
for managing repositories which can be very large.

It is the recommended tool as soon as any `git` operation is involved, or when collaboration will be a point
of focus with the repository itself.

## The Repository class[[huggingface_hub.Repository]]

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class huggingface_hub.Repository</name><anchor>huggingface_hub.Repository</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L426</source><parameters>[{"name": "local_dir", "val": ": typing.Union[str, pathlib.Path]"}, {"name": "clone_from", "val": ": typing.Optional[str] = None"}, {"name": "repo_type", "val": ": typing.Optional[str] = None"}, {"name": "token", "val": ": typing.Union[bool, str] = True"}, {"name": "git_user", "val": ": typing.Optional[str] = None"}, {"name": "git_email", "val": ": typing.Optional[str] = None"}, {"name": "revision", "val": ": typing.Optional[str] = None"}, {"name": "skip_lfs_files", "val": ": bool = False"}, {"name": "client", "val": ": typing.Optional[huggingface_hub.hf_api.HfApi] = None"}]</parameters></docstring>

Helper class to wrap the git and git-lfs commands.

The aim is to facilitate interacting with huggingface.co hosted model or
dataset repos, though not a lot here (if any) is actually specific to
huggingface.co.

> [!WARNING]
> [Repository](/docs/huggingface_hub/main/en/package_reference/repository#huggingface_hub.Repository) is deprecated in favor of the http-based alternatives implemented in
> [HfApi](/docs/huggingface_hub/main/en/package_reference/hf_api#huggingface_hub.HfApi). Given its large adoption in legacy code, the complete removal of
> [Repository](/docs/huggingface_hub/main/en/package_reference/repository#huggingface_hub.Repository) will only happen in release `v1.0`. For more details, please read
> https://huggingface.co/docs/huggingface_hub/concepts/git_vs_http.



<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>__init__</name><anchor>huggingface_hub.Repository.__init__</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L443</source><parameters>[{"name": "local_dir", "val": ": typing.Union[str, pathlib.Path]"}, {"name": "clone_from", "val": ": typing.Optional[str] = None"}, {"name": "repo_type", "val": ": typing.Optional[str] = None"}, {"name": "token", "val": ": typing.Union[bool, str] = True"}, {"name": "git_user", "val": ": typing.Optional[str] = None"}, {"name": "git_email", "val": ": typing.Optional[str] = None"}, {"name": "revision", "val": ": typing.Optional[str] = None"}, {"name": "skip_lfs_files", "val": ": bool = False"}, {"name": "client", "val": ": typing.Optional[huggingface_hub.hf_api.HfApi] = None"}]</parameters><paramsdesc>- **local_dir** (`str` or `Path`) --
  path (e.g. `'my_trained_model/'`) to the local directory, where
  the `Repository` will be initialized.
- **clone_from** (`str`, *optional*) --
  Either a repository url or `repo_id`.
  Example:
  - `"https://huggingface.co/philschmid/playground-tests"`
  - `"philschmid/playground-tests"`
- **repo_type** (`str`, *optional*) --
  To set when cloning a repo from a repo_id. Default is model.
- **token** (`bool` or `str`, *optional*) --
  A valid authentication token (see https://huggingface.co/settings/token).
  If `None` or `True` and machine is logged in (through `hf auth login`
  or [login()](/docs/huggingface_hub/main/en/package_reference/authentication#huggingface_hub.login)), token will be retrieved from the cache.
  If `False`, token is not sent in the request header.
- **git_user** (`str`, *optional*) --
  will override the `git config user.name` for committing and
  pushing files to the hub.
- **git_email** (`str`, *optional*) --
  will override the `git config user.email` for committing and
  pushing files to the hub.
- **revision** (`str`, *optional*) --
  Revision to checkout after initializing the repository. If the
  revision doesn't exist, a branch will be created with that
  revision name from the default branch's current HEAD.
- **skip_lfs_files** (`bool`, *optional*, defaults to `False`) --
  whether to skip git-LFS files or not.
- **client** (`HfApi`, *optional*) --
  Instance of [HfApi](/docs/huggingface_hub/main/en/package_reference/hf_api#huggingface_hub.HfApi) to use when calling the HF Hub API. A new
  instance will be created if this is left to `None`.</paramsdesc><paramgroups>0</paramgroups><raises>- [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError) -- 
  If the remote repository set in `clone_from` does not exist.</raises><raisederrors>``EnvironmentError``</raisederrors></docstring>

Instantiate a local clone of a git repo.

If `clone_from` is set, the repo will be cloned from an existing remote repository.
If the remote repo does not exist, a `EnvironmentError` exception will be thrown.
Please create the remote repo first using [create_repo()](/docs/huggingface_hub/main/en/package_reference/hf_api#huggingface_hub.HfApi.create_repo).

`Repository` uses the local git credentials by default. If explicitly set, the `token`
or the `git_user`/`git_email` pair will be used instead.








</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>current_branch</name><anchor>huggingface_hub.Repository.current_branch</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L560</source><parameters>[]</parameters><rettype>`str`</rettype><retdesc>Current checked out branch.</retdesc></docstring>

Returns the current checked out branch.






</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>add_tag</name><anchor>huggingface_hub.Repository.add_tag</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1241</source><parameters>[{"name": "tag_name", "val": ": str"}, {"name": "message", "val": ": typing.Optional[str] = None"}, {"name": "remote", "val": ": typing.Optional[str] = None"}]</parameters><paramsdesc>- **tag_name** (`str`) --
  The name of the tag to be added.
- **message** (`str`, *optional*) --
  The message that accompanies the tag. The tag will turn into an
  annotated tag if a message is passed.
- **remote** (`str`, *optional*) --
  The remote on which to add the tag.</paramsdesc><paramgroups>0</paramgroups></docstring>

Add a tag at the current head and push it

If remote is None, will just be updated locally

If no message is provided, the tag will be lightweight. if a message is
provided, the tag will be annotated.




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>auto_track_binary_files</name><anchor>huggingface_hub.Repository.auto_track_binary_files</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L883</source><parameters>[{"name": "pattern", "val": ": str = '.'"}]</parameters><paramsdesc>- **pattern** (`str`, *optional*, defaults to ".") --
  The pattern with which to track files that are binary.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[str]`</rettype><retdesc>List of filenames that are now tracked due to being
binary files</retdesc></docstring>

Automatically track binary files with git-lfs.








</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>auto_track_large_files</name><anchor>huggingface_hub.Repository.auto_track_large_files</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L926</source><parameters>[{"name": "pattern", "val": ": str = '.'"}]</parameters><paramsdesc>- **pattern** (`str`, *optional*, defaults to ".") --
  The pattern with which to track files that are above 10MBs.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[str]`</rettype><retdesc>List of filenames that are now tracked due to their
size.</retdesc></docstring>

Automatically track large files (files that weigh more than 10MBs) with
git-lfs.








</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>check_git_versions</name><anchor>huggingface_hub.Repository.check_git_versions</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L575</source><parameters>[]</parameters><raises>- [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError) -- 
  If `git` or `git-lfs` are not installed.</raises><raisederrors>``EnvironmentError``</raisederrors></docstring>

Checks that `git` and `git-lfs` can be run.






</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>clone_from</name><anchor>huggingface_hub.Repository.clone_from</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L598</source><parameters>[{"name": "repo_url", "val": ": str"}, {"name": "token", "val": ": typing.Union[bool, str, NoneType] = None"}]</parameters><paramsdesc>- **repo_url** (`str`) --
  The URL from which to clone the repository
- **token** (`Union[str, bool]`, *optional*) --
  Whether to use the authentication token. It can be:
  - a string which is the token itself
  - `False`, which would not use the authentication token
  - `True`, which would fetch the authentication token from the
    local folder and use it (you should be logged in for this to
    work).
  - `None`, which would retrieve the value of
`self.huggingface_token`.</paramsdesc><paramgroups>0</paramgroups></docstring>

Clone from a remote. If the folder already exists, will try to clone the
repository within it.

If this folder is a git repository with linked history, will try to
update the repository.



> [!TIP]
> Raises the following error:
>
>     - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
>       if an organization token (starts with "api_org") is passed. Use must use
>       your own personal access token (see https://hf.co/settings/tokens).
>
>     - [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
>       if you are trying to clone the repository in a non-empty folder, or if the
>       `git` operations raise errors.


</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>commit</name><anchor>huggingface_hub.Repository.commit</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1325</source><parameters>[{"name": "commit_message", "val": ": str"}, {"name": "branch", "val": ": typing.Optional[str] = None"}, {"name": "track_large_files", "val": ": bool = True"}, {"name": "blocking", "val": ": bool = True"}, {"name": "auto_lfs_prune", "val": ": bool = False"}]</parameters><paramsdesc>- **commit_message** (`str`) --
  Message to use for the commit.
- **branch** (`str`, *optional*) --
  The branch on which the commit will appear. This branch will be
  checked-out before any operation.
- **track_large_files** (`bool`, *optional*, defaults to `True`) --
  Whether to automatically track large files or not. Will do so by
  default.
- **blocking** (`bool`, *optional*, defaults to `True`) --
  Whether the function should return only when the `git push` has
  finished.
- **auto_lfs_prune** (`bool`, defaults to `True`) --
  Whether to automatically prune files once they have been pushed
  to the remote.</paramsdesc><paramgroups>0</paramgroups></docstring>

Context manager utility to handle committing to a repository. This
automatically tracks large files (>10Mb) with git-lfs. Set the
`track_large_files` argument to `False` if you wish to ignore that
behavior.



<ExampleCodeBlock anchor="huggingface_hub.Repository.commit.example">

Examples:

```python
>>> with Repository(
...     "text-files",
...     clone_from="<user>/text-files",
...     token=True,
>>> ).commit("My first file :)"):
...     with open("file.txt", "w+") as f:
...         f.write(json.dumps({"hey": 8}))

>>> import torch

>>> model = torch.nn.Transformer()
>>> with Repository(
...     "torch-model",
...     clone_from="<user>/torch-model",
...     token=True,
>>> ).commit("My cool model :)"):
...     torch.save(model.state_dict(), "model.pt")
```

</ExampleCodeBlock>



</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>delete_tag</name><anchor>huggingface_hub.Repository.delete_tag</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1204</source><parameters>[{"name": "tag_name", "val": ": str"}, {"name": "remote", "val": ": typing.Optional[str] = None"}]</parameters><paramsdesc>- **tag_name** (`str`) --
  The tag name to delete.
- **remote** (`str`, *optional*) --
  The remote on which to delete the tag.</paramsdesc><paramgroups>0</paramgroups><rettype>`bool`</rettype><retdesc>`True` if deleted, `False` if the tag didn't exist.
If remote is not passed, will just be updated locally</retdesc></docstring>

Delete a tag, both local and remote, if it exists








</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>git_add</name><anchor>huggingface_hub.Repository.git_add</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1001</source><parameters>[{"name": "pattern", "val": ": str = '.'"}, {"name": "auto_lfs_track", "val": ": bool = False"}]</parameters><paramsdesc>- **pattern** (`str`, *optional*, defaults to ".") --
  The pattern with which to add files to staging.
- **auto_lfs_track** (`bool`, *optional*, defaults to `False`) --
  Whether to automatically track large and binary files with
  git-lfs. Any file over 10MB in size, or in binary format, will
  be automatically tracked.</paramsdesc><paramgroups>0</paramgroups></docstring>

git add

Setting the `auto_lfs_track` parameter to `True` will automatically
track files that are larger than 10MB with `git-lfs`.




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>git_checkout</name><anchor>huggingface_hub.Repository.git_checkout</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1142</source><parameters>[{"name": "revision", "val": ": str"}, {"name": "create_branch_ok", "val": ": bool = False"}]</parameters><paramsdesc>- **revision** (`str`) --
  The revision to checkout.
- **create_branch_ok** (`str`, *optional*, defaults to `False`) --
  Whether creating a branch named with the `revision` passed at
  the current checked-out reference if `revision` isn't an
  existing revision is allowed.</paramsdesc><paramgroups>0</paramgroups></docstring>

git checkout a given revision

Specifying `create_branch_ok` to `True` will create the branch to the
given revision if that revision doesn't exist.




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>git_commit</name><anchor>huggingface_hub.Repository.git_commit</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1035</source><parameters>[{"name": "commit_message", "val": ": str = 'commit files to HF hub'"}]</parameters><paramsdesc>- **commit_message** (`str`, *optional*, defaults to "commit files to HF hub") --
  The message attributed to the commit.</paramsdesc><paramgroups>0</paramgroups></docstring>

git commit




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>git_config_username_and_email</name><anchor>huggingface_hub.Repository.git_config_username_and_email</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L723</source><parameters>[{"name": "git_user", "val": ": typing.Optional[str] = None"}, {"name": "git_email", "val": ": typing.Optional[str] = None"}]</parameters><paramsdesc>- **git_user** (`str`, *optional*) --
  The username to register through `git`.
- **git_email** (`str`, *optional*) --
  The email to register through `git`.</paramsdesc><paramgroups>0</paramgroups></docstring>

Sets git username and email (only in the current repo).




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>git_credential_helper_store</name><anchor>huggingface_hub.Repository.git_credential_helper_store</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L742</source><parameters>[]</parameters></docstring>

Sets the git credential helper to `store`


</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>git_head_commit_url</name><anchor>huggingface_hub.Repository.git_head_commit_url</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L779</source><parameters>[]</parameters><rettype>`str`</rettype><retdesc>The URL to the current checked-out commit.</retdesc></docstring>

Get URL to last commit on HEAD. We assume it's been pushed, and the url
scheme is the same one as for GitHub or HuggingFace.






</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>git_head_hash</name><anchor>huggingface_hub.Repository.git_head_hash</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L751</source><parameters>[]</parameters><rettype>`str`</rettype><retdesc>The current checked out commit SHA.</retdesc></docstring>

Get commit sha on top of HEAD.






</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>git_pull</name><anchor>huggingface_hub.Repository.git_pull</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L977</source><parameters>[{"name": "rebase", "val": ": bool = False"}, {"name": "lfs", "val": ": bool = False"}]</parameters><paramsdesc>- **rebase** (`bool`, *optional*, defaults to `False`) --
  Whether to rebase the current branch on top of the upstream
  branch after fetching.
- **lfs** (`bool`, *optional*, defaults to `False`) --
  Whether to fetch the LFS files too. This option only changes the
  behavior when a repository was cloned without fetching the LFS
  files; calling `repo.git_pull(lfs=True)` will then fetch the LFS
  file from the remote repository.</paramsdesc><paramgroups>0</paramgroups></docstring>

git pull




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>git_push</name><anchor>huggingface_hub.Repository.git_push</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1052</source><parameters>[{"name": "upstream", "val": ": typing.Optional[str] = None"}, {"name": "blocking", "val": ": bool = True"}, {"name": "auto_lfs_prune", "val": ": bool = False"}]</parameters><paramsdesc>- **upstream** (`str`, *optional*) --
  Upstream to which this should push. If not specified, will push
  to the lastly defined upstream or to the default one (`origin
  main`).
- **blocking** (`bool`, *optional*, defaults to `True`) --
  Whether the function should return only when the push has
  finished. Setting this to `False` will return an
  `CommandInProgress` object which has an `is_done` property. This
  property will be set to `True` when the push is finished.
- **auto_lfs_prune** (`bool`, *optional*, defaults to `False`) --
  Whether to automatically prune files once they have been pushed
  to the remote.</paramsdesc><paramgroups>0</paramgroups></docstring>

git push

If used without setting `blocking`, will return url to commit on remote
repo. If used with `blocking=True`, will return a tuple containing the
url to commit and the command object to follow for information about the
process.




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>git_remote_url</name><anchor>huggingface_hub.Repository.git_remote_url</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L764</source><parameters>[]</parameters><rettype>`str`</rettype><retdesc>The URL of the `origin` remote.</retdesc></docstring>

Get URL to origin remote.






</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>is_repo_clean</name><anchor>huggingface_hub.Repository.is_repo_clean</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1275</source><parameters>[]</parameters><rettype>`bool`</rettype><retdesc>`True` if the git status is clean, `False` otherwise.</retdesc></docstring>

Return whether or not the git status is clean or not






</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>lfs_enable_largefiles</name><anchor>huggingface_hub.Repository.lfs_enable_largefiles</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L869</source><parameters>[]</parameters></docstring>

HF-specific. This enables upload support of files >5GB.


</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>lfs_prune</name><anchor>huggingface_hub.Repository.lfs_prune</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L959</source><parameters>[{"name": "recent", "val": " = False"}]</parameters><paramsdesc>- **recent** (`bool`, *optional*, defaults to `False`) --
  Whether to prune files even if they were referenced by recent
  commits. See the following
  [link](https://github.com/git-lfs/git-lfs/blob/f3d43f0428a84fc4f1e5405b76b5a73ec2437e65/docs/man/git-lfs-prune.1.ronn#recent-files)
  for more information.</paramsdesc><paramgroups>0</paramgroups></docstring>

git lfs prune




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>lfs_track</name><anchor>huggingface_hub.Repository.lfs_track</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L828</source><parameters>[{"name": "patterns", "val": ": typing.Union[str, typing.List[str]]"}, {"name": "filename", "val": ": bool = False"}]</parameters><paramsdesc>- **patterns** (`Union[str, List[str]]`) --
  The pattern, or list of patterns, to track with git-lfs.
- **filename** (`bool`, *optional*, defaults to `False`) --
  Whether to use the patterns as literal filenames.</paramsdesc><paramgroups>0</paramgroups></docstring>

Tell git-lfs to track files according to a pattern.

Setting the `filename` argument to `True` will treat the arguments as
literal filenames, not as patterns. Any special glob characters in the
filename will be escaped when writing to the `.gitattributes` file.




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>lfs_untrack</name><anchor>huggingface_hub.Repository.lfs_untrack</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L853</source><parameters>[{"name": "patterns", "val": ": typing.Union[str, typing.List[str]]"}]</parameters><paramsdesc>- **patterns** (`Union[str, List[str]]`) --
  The pattern, or list of patterns, to untrack with git-lfs.</paramsdesc><paramgroups>0</paramgroups></docstring>

Tell git-lfs to untrack those files.




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>list_deleted_files</name><anchor>huggingface_hub.Repository.list_deleted_files</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L793</source><parameters>[]</parameters><rettype>`List[str]`</rettype><retdesc>A list of files that have been deleted in the working
directory or index.</retdesc></docstring>

Returns a list of the files that are deleted in the working directory or
index.






</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>push_to_hub</name><anchor>huggingface_hub.Repository.push_to_hub</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1289</source><parameters>[{"name": "commit_message", "val": ": str = 'commit files to HF hub'"}, {"name": "blocking", "val": ": bool = True"}, {"name": "clean_ok", "val": ": bool = True"}, {"name": "auto_lfs_prune", "val": ": bool = False"}]</parameters><paramsdesc>- **commit_message** (`str`) --
  Message to use for the commit.
- **blocking** (`bool`, *optional*, defaults to `True`) --
  Whether the function should return only when the `git push` has
  finished.
- **clean_ok** (`bool`, *optional*, defaults to `True`) --
  If True, this function will return None if the repo is
  untouched. Default behavior is to fail because the git command
  fails.
- **auto_lfs_prune** (`bool`, *optional*, defaults to `False`) --
  Whether to automatically prune files once they have been pushed
  to the remote.</paramsdesc><paramgroups>0</paramgroups></docstring>

Helper to add, commit, and push files to remote repository on the
HuggingFace Hub. Will automatically track large files (>10MB).




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>tag_exists</name><anchor>huggingface_hub.Repository.tag_exists</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1174</source><parameters>[{"name": "tag_name", "val": ": str"}, {"name": "remote", "val": ": typing.Optional[str] = None"}]</parameters><paramsdesc>- **tag_name** (`str`) --
  The name of the tag to check.
- **remote** (`str`, *optional*) --
  Whether to check if the tag exists on a remote. This parameter
  should be the identifier of the remote.</paramsdesc><paramgroups>0</paramgroups><rettype>`bool`</rettype><retdesc>Whether the tag exists.</retdesc></docstring>

Check if a tag exists or not.








</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>wait_for_commands</name><anchor>huggingface_hub.Repository.wait_for_commands</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1453</source><parameters>[]</parameters></docstring>

Blocking method: blocks all subsequent execution until all commands have
been processed.


</div></div>

## Helper methods[[huggingface_hub.repository.is_git_repo]]

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>huggingface_hub.repository.is_git_repo</name><anchor>huggingface_hub.repository.is_git_repo</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L114</source><parameters>[{"name": "folder", "val": ": typing.Union[str, pathlib.Path]"}]</parameters><paramsdesc>- **folder** (`str`) --
  The folder in which to run the command.</paramsdesc><paramgroups>0</paramgroups><rettype>`bool`</rettype><retdesc>`True` if the repository is part of a repository, `False`
otherwise.</retdesc></docstring>

Check if the folder is the root or part of a git repository








</div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>huggingface_hub.repository.is_local_clone</name><anchor>huggingface_hub.repository.is_local_clone</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L131</source><parameters>[{"name": "folder", "val": ": typing.Union[str, pathlib.Path]"}, {"name": "remote_url", "val": ": str"}]</parameters><paramsdesc>- **folder** (`str` or `Path`) --
  The folder in which to run the command.
- **remote_url** (`str`) --
  The url of a git repository.</paramsdesc><paramgroups>0</paramgroups><rettype>`bool`</rettype><retdesc>`True` if the repository is a local clone of the remote
repository specified, `False` otherwise.</retdesc></docstring>

Check if the folder is a local clone of the remote_url








</div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>huggingface_hub.repository.is_tracked_with_lfs</name><anchor>huggingface_hub.repository.is_tracked_with_lfs</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L156</source><parameters>[{"name": "filename", "val": ": typing.Union[str, pathlib.Path]"}]</parameters><paramsdesc>- **filename** (`str` or `Path`) --
  The filename to check.</paramsdesc><paramgroups>0</paramgroups><rettype>`bool`</rettype><retdesc>`True` if the file passed is tracked with git-lfs, `False`
otherwise.</retdesc></docstring>

Check if the file passed is tracked with git-lfs.








</div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>huggingface_hub.repository.is_git_ignored</name><anchor>huggingface_hub.repository.is_git_ignored</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L193</source><parameters>[{"name": "filename", "val": ": typing.Union[str, pathlib.Path]"}]</parameters><paramsdesc>- **filename** (`str` or `Path`) --
  The filename to check.</paramsdesc><paramgroups>0</paramgroups><rettype>`bool`</rettype><retdesc>`True` if the file passed is ignored by `git`, `False`
otherwise.</retdesc></docstring>

Check if file is git-ignored. Supports nested .gitignore files.








</div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>huggingface_hub.repository.files_to_be_staged</name><anchor>huggingface_hub.repository.files_to_be_staged</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L241</source><parameters>[{"name": "pattern", "val": ": str = '.'"}, {"name": "folder", "val": ": typing.Union[str, pathlib.Path, NoneType] = None"}]</parameters><paramsdesc>- **pattern** (`str` or `Path`) --
  The pattern of filenames to check. Put `.` to get all files.
- **folder** (`str` or `Path`) --
  The folder in which to run the command.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[str]`</rettype><retdesc>List of files that are to be staged.</retdesc></docstring>

Returns a list of filenames that are to be staged.








</div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>huggingface_hub.repository.is_tracked_upstream</name><anchor>huggingface_hub.repository.is_tracked_upstream</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L266</source><parameters>[{"name": "folder", "val": ": typing.Union[str, pathlib.Path]"}]</parameters><paramsdesc>- **folder** (`str` or `Path`) --
  The folder in which to run the command.</paramsdesc><paramgroups>0</paramgroups><rettype>`bool`</rettype><retdesc>`True` if the current checked-out branch is tracked upstream,
`False` otherwise.</retdesc></docstring>

Check if the current checked-out branch is tracked upstream.








</div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>huggingface_hub.repository.commits_to_push</name><anchor>huggingface_hub.repository.commits_to_push</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L288</source><parameters>[{"name": "folder", "val": ": typing.Union[str, pathlib.Path]"}, {"name": "upstream", "val": ": typing.Optional[str] = None"}]</parameters><paramsdesc>- **folder** (`str` or `Path`) --
  The folder in which to run the command.
- **upstream** (`str`, *optional*) --</paramsdesc><paramgroups>0</paramgroups><rettype>`int`</rettype><retdesc>Number of commits that would be pushed upstream were a `git
push` to proceed.</retdesc></docstring>

Check the number of commits that would be pushed upstream



The name of the upstream repository with which the comparison should be
made.






</div>

## Following asynchronous commands[[huggingface_hub.Repository]]

The `Repository` utility offers several methods which can be launched asynchronously:
- `git_push`
- `git_pull`
- `push_to_hub`
- The `commit` context manager

See below for utilities to manage such asynchronous methods.

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class huggingface_hub.Repository</name><anchor>huggingface_hub.Repository</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L426</source><parameters>[{"name": "local_dir", "val": ": typing.Union[str, pathlib.Path]"}, {"name": "clone_from", "val": ": typing.Optional[str] = None"}, {"name": "repo_type", "val": ": typing.Optional[str] = None"}, {"name": "token", "val": ": typing.Union[bool, str] = True"}, {"name": "git_user", "val": ": typing.Optional[str] = None"}, {"name": "git_email", "val": ": typing.Optional[str] = None"}, {"name": "revision", "val": ": typing.Optional[str] = None"}, {"name": "skip_lfs_files", "val": ": bool = False"}, {"name": "client", "val": ": typing.Optional[huggingface_hub.hf_api.HfApi] = None"}]</parameters></docstring>

Helper class to wrap the git and git-lfs commands.

The aim is to facilitate interacting with huggingface.co hosted model or
dataset repos, though not a lot here (if any) is actually specific to
huggingface.co.

> [!WARNING]
> [Repository](/docs/huggingface_hub/main/en/package_reference/repository#huggingface_hub.Repository) is deprecated in favor of the http-based alternatives implemented in
> [HfApi](/docs/huggingface_hub/main/en/package_reference/hf_api#huggingface_hub.HfApi). Given its large adoption in legacy code, the complete removal of
> [Repository](/docs/huggingface_hub/main/en/package_reference/repository#huggingface_hub.Repository) will only happen in release `v1.0`. For more details, please read
> https://huggingface.co/docs/huggingface_hub/concepts/git_vs_http.



<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>commands_failed</name><anchor>huggingface_hub.Repository.commands_failed</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1439</source><parameters>[]</parameters></docstring>

Returns the asynchronous commands that failed.


</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>commands_in_progress</name><anchor>huggingface_hub.Repository.commands_in_progress</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1446</source><parameters>[]</parameters></docstring>

Returns the asynchronous commands that are currently in progress.


</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>wait_for_commands</name><anchor>huggingface_hub.Repository.wait_for_commands</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L1453</source><parameters>[]</parameters></docstring>

Blocking method: blocks all subsequent execution until all commands have
been processed.


</div></div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class huggingface_hub.repository.CommandInProgress</name><anchor>huggingface_hub.repository.CommandInProgress</anchor><source>https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repository.py#L31</source><parameters>[{"name": "title", "val": ": str"}, {"name": "is_done_method", "val": ": typing.Callable"}, {"name": "status_method", "val": ": typing.Callable"}, {"name": "process", "val": ": Popen"}, {"name": "post_method", "val": ": typing.Optional[typing.Callable] = None"}]</parameters></docstring>

Utility to follow commands launched asynchronously.


</div>

<EditOnGithub source="https://github.com/huggingface/huggingface_hub/blob/main/docs/source/en/package_reference/repository.md" />