2

How do I print a welcome message containing my git aliases when I open a git bash in Windows?

chwi
  • 2,752
  • 2
  • 41
  • 66

2 Answers2

4

Simply define a HOME environment variable, (not defined in the git-bash.bat script included in msysgit).

In the directory you have chosen (for instance: %USERPROFILE%), define a .bashrc file, with the following content:

git config --get-regexp alias

(from "How to list/show Git aliases?")

That will display all your git aliases each time you open a bash session with msysgit.

alias.st status
alias.lg log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relati    ve
alias.co checkout
alias.ci commit
alias.br branch
alias.lo !sh -c 'git log $1' -
alias.impact !git ls-files -z | xargs -0n1 git blame -w -C | sed -r 's/^[^(]+\((.*) [0-9]{4}-.*/\1/' | sed -r 's/ +$//' | sort -f | uniq -c | sort -nr

However, the OP Wilhelmsen asks in the comments:

Do you know how I can omit the word alias on the print?

Sure, this is a basic bash String manipulation operation:

a=$(git config --get-regexp alias)
echo "${a//alias./}"

That will display:

st status
lg log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative
co checkout
ci commit
br branch
lo !sh -c 'git log $1' -
impact !git ls-files -z | xargs -0n1 git blame -w -C | sed -r 's/^[^(]+\((.*) [0-9]{4}-.*/\1/' | sed -r 's/ +$//' | sort -f | uniq -c | sort -nr

Note the ${a//alias./} in order to replace all 'alias.' from the String 'a' by an empty String.
And the double quotes for the echo "$..." are mandatory to keep the newlines in place. (otherwise, all the aliases would be displayed on one line).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @Wilhelmsen http://support.microsoft.com/kb/310519 or http://www.itechtalk.com/thread3595.html (ok, I didn't see your last edit to your comment) – VonC Oct 29 '12 at 13:05
  • Do you know how I can omit the word `alias` on the print? – chwi Oct 29 '12 at 13:20
  • 1
    @Wilhelmsen I have edited the answer to address your last comment/question, removing the '`alias.`' from the output. – VonC Oct 29 '12 at 13:29
4

The contents of /etc/motd are displayed on the terminal after an interactive login to the Bash shell (bash --login). If the version of Git for Windows you have omitted the file /etc/motd, create one with cat or your favorite editor.

# == Git Bash on Windows ==
#  - /etc/motd  = Message of the Day 
# - - - - - - - - - - - - -    
cat > /etc/motd
Welcome to the Git Bash Shell
- Try "pwd -W" versus "pwd -L"
- - - - - - - - -

CTRL-D

LantzR
  • 156
  • 1
  • 6