For our homework assignments, we were required to install and use Git and GitHub.
In class, I discovered that Windows users running Git Bash got some extra built-in Git functionality in their shell command prompt whereby it showed them their current branch when in a Git repository. I did not see this on my Mac and thus set out to determine how I configure this, knowing that Mac command prompts are configurable.
I googled the topic this and found a post titled "Creating a Happy Git Environment on OS X" by Trey Piepmeier which gave some steps to follow under the section titled "Bash Fanciness".
I followed the steps ...
- Edit the bash profile:
vi ~/.bash_profile
- Add the following lines to the bash profile and save:
- Source the bash profile:
. ~/.bash_profile
source /usr/local/git/contrib/completion/git-completion.bash
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='[\u@mbp \w$(__git_ps1)]\$ '
1. Could not locate the file /usr/local/git/contrib/completion/git-completion.bash:
-bash: /usr/local/git/contrib/completion/git-completion.bash:
No such file or directory
2. Could not find the command __git_ps1: -bash: __git_ps1: command not found
I needed to verify where Git was installed, so I could see if the required file was in a different directory. That's when I realized my Mac already had Git installed as part of the OS X operating system, but it was an older version and despite me having installed the latest version of Git with Homebrew, my Mac was still using the older preinstalled version. After some more reading, I discovered I had to set my $PATH variable in my bash profile to include /usr/local/bin.
Steps to fix ...
- Edit the bash profile:
- Add the following lines to the bash profile and save:
- Source the bash profile:
- Verify that you're using the most recent version of Git:
- Edit the bash profile:
- Change the following line:
- Source the bash profile:
- Update bash shell via Homebrew:
- Edit /etc/shells file:
- Add path of new shell to the end of the file and save:
- Run chsh command to change the login shell of the current user to the newly installed version:
- Restart your terminal application and verify your bash version by doing the following:
- After further research, I found that I should also source .git-prompt.sh in my bash profile:
- Add the following line and save:
- Source the bash profile:
vi ~/.bash_profile
export PATH=/usr/local/bin:$PATH
. ~/.bash_profile
git --version
I also modified my bash profile to source the Homebrew installed version of git-completion.bash, which I found under /usr/local/share/zsh/site-functions/git-completion.bash:
vi ~/.bash_profile
source /usr/local/git/contrib/completion/git-completion.bash
to:
source /usr/local/share/zsh/site-functions/git-completion.bash
. ~/.bash_profile
This eliminated the first error, but I was still getting the second error:
-bash: __git_ps1: command not found
After digging around, I then found that the Mac OS X version of the bash shell was also not the most recent, so I decided to update that too.
brew install bash
I had to add the path of this new bash shell to the /etc/shells file and then change the login shell for the current user to this version too:
sudo vi /etc/shells
/usr/local/bin/bash
chsh -s /usr/local/bin/bash [user]
bash --version
vi ~/.bash_profile
source /usr/local/Cellar/git/2.0.1/etc/bash_completion.d/git-prompt.sh
. ~/.bash_profile
Sources:
Lindsey, Buddy. “Adding Git Data to Your Bash Prompt” Buddy Lindsey. Buddy Lindsey LLC, 14 May. 2013. Web. 23 Jul. 2014.
Yarin. my fat llama. “Can't edit /etc/profile on my mac” superuser. StackExchange, 28 Feb. 2011. Web. 23 Jul. 2014.
“Which Git? How to Keep Git Up To Date on Mac” Exploring Front–end Web Development & Design. Gray Ghost Visuals Press 19 Feb. 2013. Web. 23 Jul. 2014.
Piepmeier, Trey. “Creating a Happy Git Environment on OS X” GitHub Gist. GitHub, Inc. 17 May. 2012. Web. 23 Jul. 2014.
“Which Git? How to Keep Git Up To Date on Mac” Exploring Front–end Web Development & Design. Gray Ghost Visuals Press 19 Feb. 2013. Web. 23 Jul. 2014.
Piepmeier, Trey. “Creating a Happy Git Environment on OS X” GitHub Gist. GitHub, Inc. 17 May. 2012. Web. 23 Jul. 2014.
No comments:
Post a Comment