3

My .gitconfig file is as follows:

[user]
    name = myname
    email = asdf@xyz.com
[alias]
    co = commit -am

When I'm in Git Bash and I enter:

git co "Macro changes"

I get this error message:

git: 'co' is not a git command.

Why isn't the alias being recognized?

EDIT: I'm running Windows 7. The .gitconfig file is at C:\Users\[myuserID]\.gitconfig.

Strangely, I just created another alias:

git config --global alias.st status

Then I ran

git st

which worked. But when I opened C:\Users\[myuserID]\.gitconfig, the new alias wasn't listed there. So maybe the global config file is somewhere else?

In C:\Program Files (x86)\Git\etc\profile, there's this definition of HOME:

# Set up USER's home directory
if [ -z "$HOME" -o ! -d "$HOME" ]; then
  HOME="$HOMEDRIVE$HOMEPATH"
  if [ -z "$HOME" -o ! -d "$HOME" ]; then
    HOME="$USERPROFILE"
  fi
fi

Windows command prompt tells me that %HOMEDRIVE%%HOMEPATH is P:\, and sure enough, the new alias st = status is in a .gitconfig file there, but not co = commit -am, which is odd because when I created the co alias yesterday, I was able to successfully call it.

sigil
  • 9,370
  • 40
  • 119
  • 199
  • 1
    Try editing the .gitconfig in P:\ and restart git. When you create an alias on the command-line, it will be remembered in that session. The commandline environment will not update the .gitconfig file. – Walter A Oct 20 '15 at 19:03
  • @WalterA, editing `P:\.gitconfig` did allow me to run that alias in a subsequent git session. It seems odd to me that the command line updated the `C:\ ` version of `.gitconfig` yesterday, but today it updated the `P:\ ` version. – sigil Oct 20 '15 at 19:50
  • Can you check the (Computer icon/select Properties/advanced) environment variables ? Are HOMEDRIVE and HOMEPATH set in the USER or in the SYSTEM variables ? And did you start the commandline window both times the same way (right-mouse bash-here/start-run cmd) ? – Walter A Oct 20 '15 at 21:01
  • @WalterA, they are not set in USER or SYSTEM; in all cases I started the command line window using **right click->Git Bash**. – sigil Oct 20 '15 at 21:14
  • 1
    The only explanation I can see is that you right-clicked in the explorer when the current drive was P: today and was C: yesterday. For the next few days, examine the value of %HOMEDRIVE% just after creating a commandline window. – Walter A Oct 20 '15 at 21:45

2 Answers2

2

Simply check the value of $HOME in your git bash.

If it refers to C:\Users\[myuserID], then your aliases will be recognized.

Also make sure you are using the latest bash (not the old one from msysgit): unzip PortableGit-2.6.2-64-bit.7z.exe anywhere you want, and add C:\path\to\PortableGit-2.6.2-64-bit to your path.

Then call C:\path\to\PortableGit-2.6.2-64-bit\git-bash.exe, and you are good to go.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Bash on windows almost implies that you are using cygwin, right?

If so then the cygwin version of git expects the global .gitconfig file to be placed at the cygwin user's home directory, e.g. c:\cygwin\home\username\.gitconfig or wherever cygwin is installed (run echo $HOME/.gitconfig to get exact value).

Edit: With the update on the git installation path of C:\Program Files (x86)\Git it is clearly not the cygwin git, but as you have figured out it also uses environmental variable HOME as target for storage of the global .gitconfig, although with a different value.

Regarding when I created the co alias yesterday, I was able to successfully call it, could it be that you added that alias to a .gitconfig file inside a repository?

hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • I thought about that, but I remembered running `git config --global` when I created the alias; indeed, my `C:\Users\[myuserID]\.bash_history` log (which has all of yesterday's bash commands) includes `git config --global alias.co 'commit -am'`. And neither of the `config` files from repos I was working in yesterday have the alias, it's only in `C:\Users\[myuserID]\.gitconfig`. – sigil Oct 20 '15 at 19:44