I have a Raspberry Pi running Raspbian (Debian Wheezy). I entered set in a terminal and was surprised by the long list. This seems to be almost entirely git functions — ~3700 lines of them.

__git_diff_common_options=$'--stat --numstat --shortstat --summary\n\t\t\t--patch-with-stat --name-only 

My question is, how did they get there and why?

I have occasionally used git to get packages.

I have checked all the usual suspects /etc/profile, /etc/bash.bashrc, .bashrc, .profile

I found a script /etc/bash_completion.d/git (I had never heard of bash_completion before). I have to do some more study to work out what this does, and exactly where is is called.

I still need to figure out WHY I would want to run this in every login shell when I only use git once or twice a year. (The Raspberry Pi is not exactly over endowed with RAM). This doesn't seem to happen on my Mac.

  • Also check ~/.bash_login, ~/.profile, and ~/.bash_profile if any of the exist and then double check all of them looking for source foo or . foo since it is likely that the function definitions are in yet another file and that file is being read by one of bash's init files. – terdon Oct 7 '14 at 2:36
  • 3
    This looks a bit like /etc/bash/bash.complete or something similar. – Mikel Oct 7 '14 at 3:24
  • 2
    Bash completion is simply the feature that lets you hit TAB to auto-complete filenames or options in the terminal. This file is specific to Git and lets you type (for instance) git pu + the TAB key and have bash automatically fill out git push for you. You might find this article helpful. – hololeap Oct 7 '14 at 5:39

These functions are part of the shell's completion support for git. They are maintained as part of the Git software. Debian (which Raspbian is based on) distributes the bash completion setup in the git package. The functions are located in /etc/bash_completion.d/git, in the same directory as other command completion support for bash.

All the files in /etc/bash_completion.d are loaded as part of setting up bash's programmable completion, in /etc/bash_completion. Debian's default .bashrc loads /etc/bash_completion, you can edit it out if you don't want any command-specific completion.

If you never use git, remove the git package. If you have the git package installed, then presumably you do sometimes run the git command and thus would want to have good completion for it. “I only use git rarely and I want to save a few kilobytes of RAM” is too fine a distinction even for Debian.

If you want to skip that completion file but use others, you can divert the file to a name that causes it to be skipped by /etc/bash_completion. Diverting a file is a way to tell the package manager to apply updates and removals to a file located in a different place.

dpkg-divert --add --local --rename --divert /etc/bash_completion.d/git.dpkg-diverted /etc/bash_completion.d/git
  • Thanks. This worked. There are still a lot of functions (not git). I guess what originally worried me was typing set (which I have always used to check environment) overflows my ssh buffer. (I know there are other ways) – Milliways Oct 9 '14 at 1:05
  • @Milliways In bash, you can use typeset -p +f to list only variables, not functions. – Gilles 'SO- stop being evil' Oct 9 '14 at 1:15

There are global and per-user scripts that get included at login (/etc/profile, $HOME/.profile, $HOME/.bash_profile, $HOME/.bash_login).

On most distros, the contents of some directory (like /etc/env.d/* or something similar) usually get included by the global script, where packages can put their own environment setup scripts that get sourced at every login.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.