git-lfs-completion - Man Page

Shell tab-completion script generation for Git LFS

Synopsis

git lfs completion bash
git lfs completion fish
git lfs completion zsh

Description

Outputs a script which, when executed in a session of the given shell, will implement command-line tab-completion of Git LFS commands.

Each shell requires a different set of commands to load the completion script, either for an individual session or automatically whenever a new session is started.  See the Examples section for details.

The script for each shell provides tab-completion of Git LFS command names and flags, but does not offer completion of Git terms such as the names of Git remotes, branches, or tags.  (This may change in a future release of Git LFS.)

By default, each shell’s script supports Git LFS command completion when prompted with a tab character entered following the program name git-lfs.  For instance, git-lfs [Tab] will list the available Git LFS commands such as fetch, migrate, and pull, and git-lfs pull --[Tab] will list the possible flags for the git-lfs-pull(1) command.

However, most users will be accustomed to using Git LFS as a program invoked by Git, e.g., git lfs checkout or git lfs pull.  To enable tab-completion of Git LFS commands in this case, tab-completion for regular Git commands must be active as well.  Assuming this is true, the scripts generated by the git lfs completion command should support completion of Git LFS commands when a tab character is entered following git lfs, such as git lfs [Tab] to list all available Git LFS commands or git lfs pull --[Tab] to list that command’s possible flags.  See the Shells section for details regarding Git tab-completion in the supported shells.

As is common for shell tab-completion, a space must be entered after the git-lfs or git lfs command names before the tab character will cause the Git LFS completion script to be executed.  Without the space character, any active shell tab-completion will instead search for programs whose names have a matching prefix.

The completion scripts make use of "hidden" Git LFS  commands to request completion results from the Git LFS client, specifically the git lfs __complete and git lfs __completeNoDesc commands.  These commands may be removed in the future, or their action may be altered without notice, and so users should not call them directly or consider them to be part of the officially documented Git LFS command-line interface.

Shells

The git lfs completion command supports three Unix shells, GNU Bash (Bourne Again SHell), fish, and Zsh (Z shell).  Tab-completion is configured differently in each, both in general and specifically for Git and therefore also for Git LFS.

On Windows, users who have Git LFS installed as part of the Git for Windows project have access to an emulation of the Bash shell which is packaged with Git for Windows.

Examples

Loading completions for the current shell session

To load Git LFS command completions for the current shell session only, execute the script generated by git lfs completion directly.

  • Bash:

    $ source <(git lfs completion bash)

    Note that with Bash 3.2, the source builtin command will not properly execute the output of a process substitution, and so it will be necessary to use a temporary file instead:

    $ git lfs completion bash >git-lfs-completion.bash
    $ source git-lfs-completion.bash
  • fish:

    > git lfs completion fish | source
  • zsh:

    Note that the compinit function must also be executed to enable tab-completion, as described in the Shells section.

    % source <(git lfs completion zsh)

Automatically loading completions for future shell sessions

To load Git LFS command completions in all future shell sessions, store the script generated by git lfs completion in a location where it will be read by your shell during session startup.

  • Bash:

    As mentioned in the Shells section, the bash-completion package is required by the Git LFS completion scripts for Bash, and it also provides convenient utilities which search for completion scripts in a set of defined locations and execute them during session startup.

    To load the Git LFS completion script in all future sessions started by the current user (but not other users), store the script in the bash-completion/completions directory within the location defined by the XDG_DATA_HOME environment variable, or, if that variable is not defined, the ~/.local/share directory.  For example:

    $ mkdir -p ~/.local/share/bash-completion/completions
    $ git lfs completion bash >~/.local/share/bash-completion/completions/git-lfs

    To load the completion script in all users' future sessions, store the script instead in an appropriate system directory, which on Linux may be /usr/share/bash-completion/completions, or on macOS, if bash-completion was installed using Homebrew, may be the share/bash-completion/completions directory within the location returned by the brew --prefix command. These locations will vary depending on how the bash-completion package was installed and configured, however.  For details, check the documentation relevant to your system’s bash-completion package.

  • fish:

    The fish shell searches for completion scripts in a number of locations, as described in the documentation:

    https://fishshell.com/docs/current/completions.html#where-to-put-completions

    To load the Git LFS completion script in all sessions started by the current user (but not other users), store the script in the fish/completions directory within the location defined by the XDG_CONFIG_HOME environment variable, or, if that variable is not defined, the ~/.config directory.  For example:

    > mkdir -p ~/.config/fish/completions
    > git lfs completion fish >~/.config/fish/completions/git-lfs.fish

    To load the completion script in all users' future sessions, store the script in one of the other locations searched by the shell, such under fish/completions within the shell’s system configuration directory. On Linux this is typically /etc/fish/completions.  On macOS, when the fish shell is installed using Homebrew, this would normally be the etc/fish/completions directory within the location returned by the brew --prefix command.

  • zsh:

    Note that the compinit function must also be executed to enable tab-completion, as described in the Shells section.

    To load the Git LFS completion script in all sessions, store the script as a file named _git-lfs in one of the locations listed in the fpath variable.  The specific location selected may affect whether the completion script is loaded only for sessions started by the current user or for all users' sessions, depending on how the set of paths in the fpath array is constructed.

    The following command will store the script in the first location defined in fpath:

    % git lfs completion zsh >"${fpath[1]}/_git-lfs"

    You may also prefer to store the file in another location defined in fpath, for instance, the last location, in which case ${fpath[-1]} should be used instead.

    It is also possible to add a custom location to the list in fpath and store the Git LFS completion script there.  To do this, add the commands that update the fpath variable to a startup file such as ~/.zshrc or /etc/zshrc so they will apply to all future sessions, either for the current user or for all users.

See Also

Part of the git-lfs(1) suite.

Referenced By

git-lfs(1).