1

I recently installed a variety of programs in my ubuntu environment (homestead, vagrant, virtualbox). One of those programs has caused my command line to start displaying the current branch of git along with cryptic symbols that relate to the git status. They look like this:

vagrant@homestead ~/Code/myapp (staging *<) $ cd home

where you can see it is the "staging" branch. The "*<" relates to the git status.

Here's another example:

vagrant@homestead ~/Code/myapp (master=) $ cd ..

In this case, I'm on the "master" branch and the "=" refers to the git status.

While I think it's neat, unfortunately git has also slowed my command line dramatically. Therefore, I would like to find out what has caused this change to git (it did not use to behave like this) and try to undo the features. I know that git is the reason for the slowdown because in my apps that do not have git, everything works swimmingly. I also ran "top" and noticed that git is the only thing running while my system hangs, eating up 33 to 50% of certain resources.

I thought updating to a newer version of git would help, but it made no changes. Currently I am running git version 2.7.1.

One of the following programs may have had something to do with this: drush, ruby, or compass. Unfortunately, I can't isolate which program may have affected git this way and it's possible it's a different program entirely that I can't remember installing.

Kimmo Lehto
  • 5,910
  • 1
  • 23
  • 32
Bryan Miller
  • 3,262
  • 4
  • 27
  • 51
  • None of these are related to the problem. I suspect you customized/installed a profile for your shell, `bash/zsh`. It's coming from there. Check for a `git` plugin in your shell prompt. – Babar Al-Amin Feb 17 '16 at 06:01
  • @Babar how do I check for a git plugin in my shell prompt? – Bryan Miller Feb 20 '16 at 06:32

2 Answers2

3

Check your $PS1 or $PROMPT_COMMAND variable: it might refer to a costly ps1 function which computes the state of the git repo you are in.
See for instance "git bash slow" (for Windows Linux-based shell, but the same applies on Linux)

Check if export PS1='$' (just for testing) speeds things up: that will at least confirm the issue.

The OP adds in the comment:

The issue does seem to be proportional to how large the git repository is, because I created a new directory with just 1 file in it, and git is working lightning fast in every way.

I discovered these git symbols/branch label are appearing on my command line due to this variable: PROMPT_COMMAND but I am still trying to trace down which file is generating it.
When I ran this on the command line, it made everything work at light speed again: export PROMPT_COMMAND="echo -n [$(date +%k:%m:%S)]"

You have scripts which enables/disables the prompt based on the folder, to avoid certain folders with large file and the performance cost.
See the project "jhrcz/git-prompt-autoenable" and its documentation:

PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Exactly correct.  I'll just add that the portion you're looking to remove is the `__git_ps1` function call— so likely a portion of the calculation of the `PS1` var that looks something like this: `$(__git_ps1 " (%s)")` – Slipp D. Thompson Feb 17 '16 at 06:14
  • Thanks and the above is really helpful. Do I just type "export PS1='$' into the command line in my virtual machine? I am actually using cygwin on Windows 10. I did change my /etc/profile per your instructions but there is still some hang (it might be a chunk better though). Do I need to restart my vm for it to take effect? Thanks again. – Bryan Miller Feb 17 '16 at 15:51
  • @user3089840 cygwin? You can try first the git-bash.exe packaged with the latest https://github.com/git-for-windows/git/releases: it will surely be faster than cygwin. – VonC Feb 17 '16 at 15:58
  • I will see if that makes a difference. But were you saying I can just type "export PS1='$'" directly into my command line? – Bryan Miller Feb 17 '16 at 21:25
  • @user3089840 yes provided it is a linux-based shell (cygwin or the git-bash.exe) – VonC Feb 17 '16 at 21:34
  • Using git-bash.exe moves at the same rate as cygwin. Cygwin wasn't slow either before the git branch/git status symbols began appearing on the command line (they didn't use to). Running "export PS1='$'" has no effect, the git branch/git status symbols still appear and the speed remains the same. Even adding export PS1='$' to my .profile didn't get rid of them. I also tried editing the .bashrc file to no avail. I plan to check out my git path at some point as some in the link you provided mentioned more than one possible git path, but my git on windows doesn't show the branch/symbols – Bryan Miller Feb 18 '16 at 03:00
  • @user3089840 are you using the latest 2.7.1.2 git-for-windows? On which brand of Windows are you on? – VonC Feb 18 '16 at 05:57
  • My version of git is 2.7.1 while in my virtual machine. I have Windows 10. – Bryan Miller Feb 18 '16 at 15:24
  • VM? Do you have performance issue with git in your VM or on Windows? – VonC Feb 18 '16 at 15:34
  • In my VM only, but I didn't used to. – Bryan Miller Feb 20 '16 at 06:31
  • @user3089840 are those performance issue permanent (even on a new empty git repo), or visible only in a specific existing repo? – VonC Feb 20 '16 at 06:34
  • I tried creating a new drupal project without Git, and I could cd in lightning quick. I tried doing a git init, and I could still cd in and out just fine UNTIL I made my first git add --all which took what felt like 1 minute. THEN, cd-ingin and out not so quick anymore. – Bryan Miller Feb 20 '16 at 22:03
  • @user3089840 is this a volume issue (git add too many files or too big?) Would the issue persists when you add just one file? – VonC Feb 20 '16 at 22:19
  • I tried adding about 5 files, and hit "git status." It took about 4 seconds. Even "cd"-ing in and out of the directory got slowed down after the first "git add". I appreciate your patience in trying to help me solve this mystery. – Bryan Miller Feb 20 '16 at 22:25
  • The issue does seem to be proportional to how large the git repository is, because I created a new directory with just 1 file in it, and git is working lightning fast in every way. – Bryan Miller Feb 21 '16 at 00:14
  • I discovered these git symbols/branch label are appearing on my command line due to this variable: PROMPT_COMMAND but I am still trying to trace down which file is generating it. When I ran this on the command line, it made everything work at light speed again: export PROMPT_COMMAND="echo -n [$(date +%k:%m:%S)]" – Bryan Miller Feb 21 '16 at 03:58
  • @user3089840 Interesting. I have included your last two comments in the answer for more visibility. And I mention an alternative prompt which might be faster/configurable. – VonC Feb 21 '16 at 06:08
  • Thanks for your help and I upvoted you for all your effort. I do appreciate your work on this, but I think I'm going to add my own solution. – Bryan Miller Feb 22 '16 at 16:15
1

Installing "drush" caused the changes to the command line. You will notice after installation of "drush" is complete, it will mention it added a handful of lines to your .bashrc file, including this one:

# Include Drush prompt customizations.
if [ -f "/home/vagrant/.drush/drush.prompt.sh" ] ; then
  source /home/vagrant/.drush/drush.prompt.sh
fi

If you open the file it references (/home/vagrant/.drush/drush.prompt.sh) you will see that this is where both PROMPT_COMMAND and PS1 are being modified.

Instead of completely deleting or overwriting drush.prompt.sh, it may be best to modify it so as not to lose drush command line customizations. However, to completely overwrite it you can add something like the following to your .bashrc file. The .bashrc file located in your ~ directory will modify only your profile. Here's an example that displays some nice info and a git status that works much faster:

TZ='America/Chicago'; export TZ
export PROMPT_COMMAND="echo -n [$(date +%r)]"; 
export PS1='\[\e]0;\w\a\] \[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\] $((git symbolic-ref -q HEAD || git rev-parse -q --short $

You may not need to TZ line or can adjust it accordingly.

Here's another nice option:

function mycp {
    EXITSTATUS="$?"
    YELLOW="$(tput setaf 3)"
    RED="\[\033[0;31m\]"
    GREEN="\[\e[0;32m\]"
    BLUE="\[\e[34m\]"
    OFF="\[\033[m\]"
    HOST="\h"
    USER="\u"
    DIR="\w"
    NEWLINE="\n"
    DATE="\d"
    TIME="\T"
    BRANCH="`git branch 2> /dev/null | grep -e ^* | sed -E  s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`"

    PROMPT="\[\033]0;${USER}@${HOST}: \w\007\n${YELLOW}${TIME} ${DATE} ${GREEN}${USER}@${HOST} ${RED}${BRANCH}"

    if [ "${EXITSTATUS}" -eq 0 ]
    then
        PS1="${PROMPT} ${BLUE}[${GREEN}${EXITSTATUS}${BLUE}]${OFF}\n${GREEN}\w \$${OFF}   "
    else
        PS1="${PROMPT} ${BLUE}[${GREEN}${EXITSTATUS}${BLUE}]${OFF}\n${GREEN}\w \$${OFF}   "
    fi
}
PROMPT_COMMAND=mycp
Bryan Miller
  • 3,262
  • 4
  • 27
  • 51