Package management in Git for Windows (Git Bash)? - windows

I'm reading the github wiki for git-for-windows and it says that msys2 bundles pacman: https://github.com/git-for-windows/git/wiki/Package-management
But when I invoke it I get:
$ pacman
bash: pacman: command not found
Does anyone have an idea what is going on?
Which git version does this wiki refer to?
Is there a way to install additional packages to msys2 inside Git for windows?

As mentioned in issue 397:
This is intended. We do not ship pacman with Git for Windows.
If you are interested in a fully fledged package manager maintained environment you have to give the Git for Windows SDK a try.
The bash that you see in the latest git for Windows (2.5.3), which is a more recent bash than the old msysgit one, is only there to execute git commands.
It is not a full-fledged linux environment to install any third-party package.
Warning: dhj reports in the comments
Do not link your existing git for windows with the msys2 main system by using a directory junction.
If you uninstall it will decide that linked directory belongs to it and DELETE YOUR ENTIRE HOME DIRECTORY including sub-directories like "Downloads".
Beware dealing with msys2.
I don't know if the same is true for the git for windows SDK, but BE CAREFUL trying to get pacman from other systems integrated with git for windows.

Git for Windows (https://gitforwindows.org/ or https://git-scm.com/downloads) has Git Bash but it does not include tree.
tree is available via pacman (Package Manager), but that is only available if you install "Git for Windows SDK" (scroll to the bottom of https://gitforwindows.org/ which provides a link to download installer for it from https://github.com/git-for-windows/build-extra/releases/latest)
The accepted answer was very helpful. They mention that git-for-windows was not meant to include pacman in the default install.
So I installed "Git for Windows SDK", then in its bash prompt (SDK-64) I ran the
following to install current tree v1.7.0-1 (as of this posting Aug 30, 2018):
[SDK-64: Bash Terminal for Git for Windows SDK]
pacman -S tree
...
Proceed with installation? [Y/n] Y
On my system, Git for Windows SDK is installed under: C:\git-sdk-64, so from my Git for Windows Bash shell (which did not have tree installed), I copied it over tree.exe to its /usr/bin directory, e.g.
[MINGW64: Bash Terminal for Git for Windows]
cd /usr/bin
cp /c/git-sdk-64/usr/bin/tree.exe .
Now I can run tree v1.7.0 from both Git Bash shells.
To make it even easier for others and maybe myself on a future machine, I looked at where pacman was getting the tree package from by running the following in my Git for Windows SDK Bash terminal:
$ pacman -S --info tree
Repository : msys
Name : tree
Version : 1.7.0-1
Description : A directory listing program displaying a depth indented list of files
Architecture : x86_64
...
The key thing here is that pacman is getting tree from the "msys" repository (FYI: even though it says msys, it really is using msys2), so I looked at /etc/pacman.d/mirrorlist.msys and the first mirror points to http://repo.msys2.org/msys/$arch/
So next time you want a package that is NOT in Git for Windows, you can download them from: http://repo.msys2.org/msys/x86_64/ (for 64-bit) or from http://repo.msys2.org/msys/i686/ (32-bit)
e.g. direct download link for tree v1.7.0-1
64-bit: http://repo.msys2.org/msys/x86_64/tree-1.7.0-1-x86_64.pkg.tar.xz
or https://sourceforge.net/projects/msys2/files/REPOS/MSYS2/x86_64/tree-1.7.0-1-x86_64.pkg.tar.xz
32-bit: http://repo.msys2.org/msys/i686/tree-1.7.0-1-i686.pkg.tar.xz
or https://sourceforge.net/projects/msys2/files/REPOS/MSYS2/i686/tree-1.7.0-1-i686.pkg.tar.xz
FYI: Git SCM's Window's download at https://git-scm.com/download/ pulls the latest from Git for Windows GitHub (https://github.com/git-for-windows/git from the https://github.com/git-for-windows/git/releases/ link)

I did not want to move from my already working Git for Windows installation so I improvised a bit:
Install Git for Windows SDK somewhere else. You'll need more than 3 GB of free space for that.
Copy ${git-sdk}/usr/bin/pacman.exe to ${git}/usr/bin
Copy ${git-sdk}/etc/pacman.conf and ${git-sdk}/etc/pacman.d to ${git}/etc
Copy ${git-sdk}/var to ${git}/
That's all. You can now open your Git Bash and run pacman -S python to install packages on your existing Git for Windows setup.
You will need write access to Git for Windows directory. Also, your pacman now thinks it has a lot of packages installed (from SDK) but it did not stop me from using it.

"Git for Windows SDK" is 5.33GB compared to "Git for Windows" 691MB compared to "Portable Git" 275MB. I use the lean and mean Portable Git. At first, it seems hopeless trying to restore and use pacman in the latter two flavors of Git (msys2), because Google excluded ALL metadata files in /var/lib/pacman/local. Please read this official explanation:
https://wiki.archlinux.org/index.php/Pacman#.22Failed_to_commit_transaction_.28conflicting_files.29.22_error
Without those metadata files, you don't know the exact collection and version of the msys2 packages Google selected to build a release of those 2 flavors of Git. If you force to install or copy the current version of msys2 packages, you run the risk of version mismatch with git binaries Google built and tested.
Well, that's until I discover this file: /etc/package-versions.txt, the laundry list of matching msys2 packages and versions. Now there is a definitive source in github. Here is how I restore pacman in Portable Git (commands can be copy & paste into git-bash shell all at once):
Step 1: Run these commands to download /etc/pacman.conf and 3 packages: pacman, pacman-mirrors and msys2-keyring. See my Dec 9, 2022 comment below on why you need zstd in .xz format. These packages/versions were tested on both 32 and 64-bit Portable Git 2.38.1:
if [[ "$HOSTTYPE" == "i686" ]]; then
pacman="
pacman-6.0.0-4-i686.pkg.tar.zst
pacman-mirrors-20210703-1-any.pkg.tar.zst
msys2-keyring-1~20210213-2-any.pkg.tar.zst
"
zstd=zstd-1.5.0-1-i686.pkg.tar.xz
else
pacman="
pacman-6.0.1-18-x86_64.pkg.tar.zst
pacman-mirrors-20220205-1-any.pkg.tar.zst
msys2-keyring-1~20220623-1-any.pkg.tar.zst
"
zstd=zstd-1.5.2-1-x86_64.pkg.tar.xz
fi
for f in $pacman; do curl https://repo.msys2.org/msys/$HOSTTYPE/$f -fo ~/Downloads/$f; done
curl -L https://github.com/mcgitty/pacman-for-git/raw/main/$zstd -o ~/Downloads/$zstd
curl https://raw.githubusercontent.com/msys2/MSYS2-packages/7858ee9c236402adf569ac7cff6beb1f883ab67c/pacman/pacman.conf -o /etc/pacman.conf
Step 2: Unpack them at the root then restore pacman with these commands:
cd /
tar x --xz -vf ~/Downloads/$zstd usr
for f in $pacman; do tar x --zstd -vf ~/Downloads/$f usr etc 2>/dev/nul; done
mkdir -p /var/lib/pacman
pacman-key --init
pacman-key --populate msys2
pacman -Syu
Step 3: The next set of commands restore all matching metadata (be patient). Like the zstd packages in Step 1, this relies on my public github repo pacman-for-git to provide the git-sdk commit ID of each Portable Git release, which I'll do my best to update:
t=`grep -E 'mingw-w64-[ix_0-9]+-git ' /etc/package-versions.txt`
t=`curl -sL https://github.com/mcgitty/pacman-for-git/raw/main/version-tags.txt|grep "$t"`
[[ "$t" == "" ]] && echo "ERROR: Commit ID not logged in github pacman-for-git." && read
b=64 && [[ "$t" == *-i686-* ]] && b=32
URL=https://github.com/git-for-windows/git-sdk-$b/raw/${t##* }
cat /etc/package-versions.txt | while read p v; do d=/var/lib/pacman/local/$p-$v;
mkdir -p $d; echo $d; for f in desc files mtree; do curl -fsSL "$URL$d/$f" -o $d/$f;
done; [[ ! -f $d/desc ]] && rmdir $d; done
Step 4: Now, is it too much to ask for 'make' and 'zip'?
pacman -S make zip
Voilà, still just a 337MB mean little environment that can expand and upgrade!

There seems to be a documented way to do this without having to install the Git for Windows SDK (which is very large). I was given the link to this info by PhilipOakley when I asked about all this on GitHub issue #1912.
Here's the current text of the Git for Windows GitHub wiki page about it:
##Install inside MSYS2 proper
###Please note that this scenario is not officially supported by Git for Windows
(The reason this is unsupported is that there are no volunteers to support that scenario.)
This guide assumes that you want the 64-bit version of Git for Windows.
Git for Windows being based on MSYS2, it's possible to install the git package into an existing MSYS2 installation. That means that if you are already using MSYS2 on your computer, you can use Git for Windows without running the full installer or using the portable version.
Note however that there are some caveats for going this way. Git for Windows created some patches for msys2-runtime that have not been sent upstream. (This had been planned, but it was determined in issue #284 that it would probably not be happening.) This means that you have to install Git for Windows customized msys2-runtime to have a fully working git inside MSYS2.
Here the steps to take:
Open an MSYS2 terminal.
Edit /etc/pacman.conf and just before [mingw32] (line #71 on my machine), add the git-for-windows packages repository:
[git-for-windows] Server = https://wingit.blob.core.windows.net/x86-64
and optionally also the MINGW-only repository for the opposite architecture (i.e. MINGW32 for 64-bit SDK):
[git-for-windows-mingw32] Server = https://wingit.blob.core.windows.net/i686
Authorize signing key (this step may have to be repeated occasionally until https://github.com/msys2/msys2/issues/62 is fixed)
curl -L https://raw.githubusercontent.com/git-for-windows/build-extra/master/git-for-windows-keyring/git-for-windows.gpg | pacman-key --add - && pacman-key --lsign-key 1A9F3986
Then synchronize new repository
pacboy update
This updates msys2-runtime and therefore will ask you to close the window (not just exit the pacman process). Don't panic, simply close all currently open MSYS2 shells and MSYS2 programs. Double-check Task Manager and kill pacman.exe it's still running after the window is closed, because it can linger. Once all are closed, start a new terminal again.
Then synchronize again (updating the non-core part of the packages):
pacboy update
And finally install the Git/cURL packages:
pacboy sync git:x git-doc-html:x git-doc-man:x git-extra: curl:x
Finally, check that everything went well by doing git --version in a MINGW64 shell and it should output something like git version 2.14.1.windows.1 (or newer).
#VonC pointed out in the comments that there is discussion about possible additional steps needed in this approach, around half-way down the discussion at https://github.com/git-for-windows/git/issues/2688.
And now, potentially a new way to achieve the required result too:
https://github.com/git-for-windows/git/issues/2688#issuecomment-772311418

Tested on msys2 20190524 on Windows 10 x86_64 1909 10.0.18363.752 and msys2 20220128 on Windows 11 x86_64 21H2 10.0.22000.434
Using regular Git for Windows.
Install msys2 (Version 20190524 is tested.) or Git for Windows SDK. (Not fully tested, but it should work.) Both include PacMan and Git.
Using VFS for Git for Windows or Scalar for Git for Windows (Aka Microsoft git). Method #1 (with some limitations)
Install VFSForGit ( https://github.com/microsoft/VFSForGit ).
Install Microsoft git ( https://github.com/microsoft/git ) with this option "Git from the command line and also from 3rd-party software" enabled.
Create a symbolic link named "git" in msys64\usr\bin\ pointing to C:\Program Files\Git\bin\git.exe . Execute the following command in cmd.exe, not in bash. mklink git "C:\Program Files\Git\bin\git.exe"
Clone a new gvfs repo. gvfs clone https://dev.azure.com/somebody/_git/somerepo. Only the gvfs command can not be executed on msys2.
Use the git command as you are on msys2 normally.
Using VFS for Git for Windows or Scalar for Git for Windows. Method #2
Virtual Filesystem for Git (formerly was GVFS. Official website https://vfsforgit.org/ ) is recommended. Version 2.22 & 2.26 are tested. Scalar (Official website https://github.com/microsoft/scalar ) is NOT recommended, nor completely tested.
Install GVFS and Git for Windows with GVFS patch. Or install Scalar for Git and Git for Windows with Scalar patch. NOT BOTH on the same machine. The default installation destination is C:\Program Files\Git.
Install msys2 x64 somewhere other than C:\Program Files\Git. By default, it is in C:\msys64.
Copy files and subfolders of msys2 (except /etc and git binaries. The msys2 comes without git from factory.) to Git for Windows VFS edition, and copy /etc/pacman.d and /etc/pacman.conf in msys64 folder to Git installation folder, overwrite existing files. It will update msys2 and MinGW runtime to the latest version. For PacMan, the necessary files are /usr/bin/pac* ; /etc/pacman.conf ; /etc/pacman.d/ ; /var ; /usr/bin/msys* ; .(Not fully tested.)
Setup terminal applications. Run C:\Program Files\Git\bin\bash.exe will launch the bash of Git for Windows. Run C:\Program Files\Git\usr\bin\bash.exe will launch bash of msys2. Configure the path of bash for terminal programs, such as Hyper Terminal. Since Git is in the system folder, terminal programs should be Run as administrator.
Config $PATH the environmental variable for GVFS. Run this command in Git Bash. export PATH=$PATH:/C/Program\ Files/GVFS or export PATH=$PATH:"/C/Program Files/GVFS". Or set environmental variables for GVFS in the system property of the control panel. Relogin to take effect. Sometimes this configuration does not work, but PacMan can still run.
Fix PacMan. Set executable permission for binaries. Fox example. chmod +x /usr/bin/pacman ; pacman-key --init ; pacman-key --populate msys2 ; pacman-key --refresh-keys ; pacman --sync pacman --refresh --sysupgrade --sysupgrade --overwrite "*" . Use the option --overwrite \* because some packages were installed by Git for Windows instead of PacMan.

pacman is compressed using zstd now.
So updated #michael-chen 's scenario (i use wsl's unzstd):
for f in pacman-6.0.1-25-x86_64.pkg.tar.zst pacman-mirrors-20221016-1-any.pkg.tar.zst msys2-keyring-1~20221024-1-any.pkg.tar.zst; do curl https://repo.msys2.org/msys/x86_64/$f -o ~/Downloads/$f; done
cd /
tar --use-compress-program=unzstd -xvf ~/Downloads/msys2-keyring-1~20221024-1-any.pkg.tar.zst usr
tar --use-compress-program=unzstd -xvf ~/Downloads/pacman-mirrors-20221016-1-any.pkg.tar.zst etc
tar --use-compress-program=unzstd -xvf ~/Downloads/pacman-6.0.1-25-x86_64.pkg.tar.zst usr
mkdir -p /var/lib/pacman
pacman-key --init
pacman-key --populate msys2
pacman -Sy
export URL=https://github.com/git-for-windows/git-sdk-64/raw/main
cat /etc/package-versions.txt | while read p v; do d=/var/lib/pacman/local/$p-$v; mkdir -p $d; echo $d; for f in desc files install mtree; do curl -sSL "$URL$d/$f" -o $d/$f; done; done

Copying pacman from msys2 works for me, at the end most people forget that you can use pacman for self update as pacman -Syy msys/pacman
Run in msys pacman -Ql pacman
Copy files listed that match
/etc/*.conf
/usr/bin
/usr/include
/usr/lib
/var/lib
And copy databases as well
/etc/pacman
At this point I already have a working pacman,I check it with pacman -Ss pacman but there are missing files so I run self refresh
pacman -Syy msys/pacman

Related

How do I install Git for Windows software to a specific directory?

I have just downloaded the latest Git for Windows installer, v2.4. It appears to want to install to the standard Windows "Program files" (with-spaces-in-name) directory.
Since I have all my development code in a folder called (simply) "/bin" -- I want to see if there's a command line option or parameter to change the install directory.
In my case, these days I use a environment variable such as GIT_HOME for important software like git; so it would be useful if there was a way to apply that to things like git commands, etc once I have the program installed.
possibly related:
How do I change the directory in Git Bash with Git for Windows?
I also came across a few questions asking: "whereis git". That's answered above, however I take that as an indicator that others may want git somewhere else too.
To start the installer with a different installation path you can open a CMD terminal in the same directory as the installer executable and pass in an option parameter of /DIR="x:\dirname"
For instance, if you have version 2.17.0 for Windows 64bit and you want to install git to D:\git, you would run:
Git-2.17.0-64-bit.exe /DIR="D:\git"
The installer will launch as usual and you need to walk through the other options, but the install location will be the path specified.
Since I just ran into this problem because my SSD is filling up, I figured I'd share the solution I came to on Windows 11 with Git v. 2.37.2.
The best way I could figure was to uninstall Git, then in CMD Prompt use the suggested command from the Git website with an appended --location/ -l flag:
winget install --id Git.Git -e --source winget --location [drive:/directory]
where [drive:/directory] is your target for the install. Had no issues and verified it worked with a project.

On OSX using sourcetree / git-svn getting "Can't locate SVN/Core.pm in #INC "

I'm using OSX and want get a svn repo into a local git repo using sourcetree.
When I add a bookmark using sourcetree using SVN URL, thus sourcetree knows it's a SVN url, but when I click the clone button, it reports an error like following:
Can't locate SVN/Core.pm in #INC (#INC contains: /usr/local/git/lib/perl5/site_perl /Applications/SourceTree.app/Contents/Resources/git_local/lib/perl5/site_perl /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at /Applications/SourceTree.app/Contents/Resources/git_local/lib/perl5/site_perl/Git/SVN/Editor.pm line 5.
BEGIN failed--compilation aborted at /Applications/SourceTree.app/Contents/Resources/git_local/lib/perl5/site_perl/Git/SVN/Editor.pm line 5.
Compilation failed in require at /Applications/SourceTree.app/Contents/Resources/git_local/libexec/git-core/git-svn line 81.
BEGIN failed--compilation aborted at /Applications/SourceTree.app/Contents/Resources/git_local/libexec/git-core/git-svn line 81.
I don't how to get it through. Can anyone give me a pointer on how to do this?
I hit this missing SVN/Core.pm issue recently with el capitain.
Fix I used was from Paul Schreiber's blog :
sudo mkdir /Library/Perl/5.18/auto
sudo ln -s /Applications/Xcode.app/Contents/Developer/Library/Perl/5.18/darwin-thread-multi‌-2level/SVN /Library/Perl/5.18/darwin-thread-multi-2level
sudo ln -s /Applications/Xcode.app/Contents/Developer/Library/Perl/5.18/darwin-thread-multi‌-2level/auto/SVN /Library/Perl/5.18/auto/
Commenters below, say this worked on sierra and high sierra too.
Or, if you don't have Xcode, just CommandLineTools (this is on ElCapitan 10.11.6):
sudo ln -s /Library/Developer/CommandLineTools/Library/Perl/5.18/darwin-thread-multi-2level/SVN /usr/local/git/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/SVN
sudo ln -s /Library/Developer/CommandLineTools/Library/Perl/5.18/darwin-thread-multi-2level/auto/SVN /usr/local/git/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/auto/SVN
If you previously linked some older version or just made a mistake so it gives you: File exists, then you should first do
sudo unlink /usr/local/git/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/SVN
for whichever file was reported as already existent, of course.
EDIT Dir doesn't exist: (suggested by #rogeriopradoj)
mkdir -p /usr/local/git/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level
EDIT Sierra:
After upgrading to Sierra I lost CommandLineTools, so I just had to reinstall it and everything was back to normal.
This will prompt you to install just the CommandLineTools, not the whole XCode.
xcode-select --install
Hope this helps someone :)
In my case, it is because different versioned perl was installed by brew as dependency of some formula, and override the system's default version.
So the resolution for me is to relieve the overridden as described following.
when type which perl and perl -v, I find it not the system default version:
# locate programs
faner#MBP-FAN:~|⇒ whereis perl
/usr/bin/perl
# locate a program file in the user's path
faner#MBP-FAN:~|⇒ which perl
/usr/local/bin/perl
faner#MBP-FAN:~|⇒ perl -v
This is perl 5, version 26, subversion 1 (v5.26.1) built for darwin-thread-multi-2level
which should be v5.18.2 according to the git svn error messages.
I guess it is because the different versioned perl was installed by brew as dependency of some formula, and override the system default version.
faner#MBP-FAN:~|⇒ brew uses perl --installed
subversion
To prove it, try to move /usr/bin before /usr/local/bin in $PATH, then perl was fallback to the system's default version:
faner#MBP-FAN:~|⇒ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
faner#MBP-FAN:~|⇒ PATH=/usr/bin:$PATH
faner#MBP-FAN:~|⇒ echo $PATH
/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
faner#MBP-FAN:~|⇒ whereis perl
/usr/bin/perl
faner#MBP-FAN:~|⇒ which perl
/usr/bin/perl
faner#MBP-FAN:~|⇒ perl -v
This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)
and perl -V list the #INC just satisfy the Can't locate SVN/Core.pm in #INC requirements:
faner#MBP-FAN:~|⇒ perl -V
Summary of my perl5 (revision 5 version 18 subversion 2) configuration:
#INC:
/Library/Perl/5.18/darwin-thread-multi-2level
/Library/Perl/5.18
/Network/Library/Perl/5.18/darwin-thread-multi-2level
/Network/Library/Perl/5.18
/Library/Perl/Updates/5.18.2
/System/Library/Perl/5.18/darwin-thread-multi-2level
/System/Library/Perl/5.18
/System/Library/Perl/Extras/5.18/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.18
type git svn and everything works well!
faner#MBP-FAN:~|⇒ git svn --version
git-svn version 2.15.1 (Apple Git-101) (svn 1.9.7)
Manage to fix the same issue by changing the first line in /usr/local/Cellar/git/2.29.2/libexec/git-core/git-svn
to
#!/usr/local/bin/perl
Plus to the highest answer,
If you are using souceTree, simply paste command line may not work immediately.
In that case, you may need to check git used in your sourceTree, which should be set as System git.
Xcode 11.4 no longer includes SVN/Core.pm in its Perl bindings!
If you've never installed the commandline tools and Xcode 11.4 is the first version you've run you will see this issue. Running xcode-select --install returns error: command line tools are already installed, use "Software Update" to install updates, which is accurate but non-obvious that your installed commandline tools differ from what you would get if installed outside of Xcode 11.4. The solution is to first remove these, then install the commandline tools using xcode-select.
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
Thanks Marko, I did find that on ElCapitan 10.11.3 I had to symlink to a different area. Not sure why, but it works.
sudo ln -s /Library/Developer/CommandLineTools/Library/Perl/5.18/darwin‌​-thread-multi-2level‌​/SVN /Applications/SourceTree.app/Contents/Resources/git_local/li‌​b/perl5/site_perl/5.‌​18.2/darwin-thread-m‌​ulti-2level/SVN
sudo ln -s /Library/Developer/CommandLineTools/Library/Perl/5.18/darwin‌​-thread-multi-2level‌​/auto/SVN /Applications/SourceTree.app/Contents/Resources/git_local/li‌​b/perl5/site_perl/5.‌​18.2/darwin-thread-m‌​ulti-2level/auto/SVN
I got the same issue on Macos Mojave 10.14.1. Because I used the built-in version of git, and it's too lower(2.19.0). I fixed it by upgrade git to the latest version(2.21.0), and I found 2.19.1 also has no this issue.
The solution for me was to delete the password entry in the OSX key ring app, and have git svn re-create it. My key entry has been created earlier (by svn I suppose), and it seems that git cannot use this key entry (nor fix it nor add a second one).
The long story: I noticed that when unsing "system git" in SourceTree, there seemed to be a problem storing the credentials. When I entered the same git command (that SourceTree is issuing) on the command-line, git kept prompting me for my password each time.
Then I found https://stackoverflow.com/a/39800112/580672
If you are interested, my setup was:
No Xcode, only Command-Line tools (so I adapted the paths as mentioned in a post above ( https://paulschreiber.com/blog/2015/11/09/fixing-git-svn-on-os-x-el-capitan/comment-page-1/#comment-437843 )
Homebrew has svn and perl installed
I had tried with no success:
"embedded git" (yields the #INC error)
"system git" (different error: "Username: Use of uninitialized value $ret in chomp at /usr/local/Cellar/git/2.21.0/share/perl5/Git.pm line 596.")
put usr/bin in front of my PATH as suggested above
force-uninstalled perl in homebrew
All without success. The solution was system git and the key entry, as stated above.
I've found that the best solution is to expand the list of directories in #INC using an export
export PERL5LIB=/Applications/Xcode.app/Contents/Developer/Library/Perl/5.18
Referenced from: https://perlmaven.com/how-to-change-inc-to-find-perl-modules-in-non-standard-locations

How to update my version of git on OSX 10.8

I'm on OSX 10.8.2 and I'm running git git v1.7.4.4
I just installed git on a remote server and it's version 1.11.x. I'm I would like to be running the same version of the software but I cannot figure out how to update git on my laptop.
I attempted to follow the steps listed here, which instruct to download the git-OSX-installer, run the install (which ran smoothly) and then do:
$ sudo mkdir -p /usr/local/bin
$ sudo ln -s /usr/local/git/bin/git /usr/local/bin/git
But after this I do git --version and it's still 1.7.4.4. Did I just reinstall the same version? Or did I install a newer version somewhere else?
I've been reading similar questions and I think the issue is that OSX ships with an old version of git installed in a different location then where the git-osx-installer or mac ports will put it. But I'm not sure how to correct this. Thanks in advance for your advice.
Update:
which git returns:
/usr/bin/git
echo $PATH returns:
/opt/local/bin:/opt/local/sbin:/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin
Update2:
ESL ~/Downloads$ export PATH=/usr/local/bin:$PATH
ESL ~/Downloads$ which git
/usr/local/bin/git
ESL ~/Downloads$
ESL ~/Downloads$ git --version
git version 1.8.1.3
It appears I installed the newer git version in local. So should I add the export PATH=/usr/local/bin:$PATH to my .bash_profile? Is it a problem that both versions of git are installed?
I added export PATH=/usr/local/bin:$PATH to the bottom of my ~/.bash_profile and now the new version of git runs.
The best way to update any binary on a Mac OSX machine is to use the package(s) developed specifically for Mac (a .dmg or .pkg download).
In the case of git this is at: http://git-scm.com/download/mac
(clicking on this link should automatically start the download of the latest version of git for Mac).
However, in this case (at least for my 10.8.3 MacBook) this was not quite the whole story: the package installs git in /usr/local/git and then adds that path at the end of $PATH - which defeats the whole purpose IMO.
I have manually modified my .bashrc so as to have something similar to what suggested above:
export PATH=/usr/local/git/bin:$PATH
Once you do that, you should see the correct version of git being picked:
$ git --version
git version 1.8.2.2
Note that this won't work for any app that is launched interactively (eg, via the docking bar) - you'll have to run the additional script provided in the downloaded package; see the README for instructions.
Since /usr/bin shows up before /usr/local/bin in your path, the git executable in /usr/bin will be given precedence.
try this in your shell:
export PATH=/usr/local/bin:$PATH
which git
On a side note, I'd strongly recommend using homebrew for managing installations such as this on macos
I had a similar issue in Cygwin (linux environment compiled for windows). I would do
which git
and it would respond with the correct location of the updated git compiled from source, but wouldn't actually use it until I did
hash -r git
I don't claim to understand what this did or why it had to be done, but after that git --version replied with '1.8.2.rc0.22.gb3600c3' which was clearly no longer the old git shipped with Cygwin. This may not apply to OSX, but give it a shot if which git is locating the updated binary.

Installing Git separately from Github for Mac

I've installed Github for Mac.
I've realised that I need to get to the command line to do some stuff.
There is an option in Guthub for Mac to install a command line. All this seems to do is create an alias called Github in /usr/local/bin that points back to the Github for Mac application.
Double clicking it opens a terminal window and then Github for Mac.
Any ideas how to get Git to work in a command line?
Its a relatively clean version of Lion OS X
Git is included in the command line tools package provided by Apple that can be downloaded at https://developer.apple.com/downloads/index.action
It is also included with Xcode, which can be downloaded from either the Mac App Store or from the above link.
Assuming you'd rather not install either of these you can also obtain Git by downloading it from http://git-scm.com/downloads
Hope that helps.
https://help.github.com/articles/set-up-git#platform-mac
Should walk you though installing it.
I highly recommend installing Homebrew, which does a great job of keeping up with the latest git releases.
Once Homebrew is installed, it's as simple as:
brew install git
Note that, from May 2013, you now have with "GitHub for Mac" both:
the GUI
the CLI (Command-Line Interface)
See the blog post "Installing Git from GitHub for Mac"
you can now easily install Git for use on the command line, without needing to download any separate packages.
Even the git updates are taken care for you:
And whenever we update the version of Git included with GitHub for Mac, you'll get the changes automatically – no work required on your part!
you may notice some changes to the Preferences window.
On the newly renamed "Advanced" tab, simply click "Install Command Line Tools".
You'll be prompted for an administrator password so that Git can be installed into /usr/local/bin, and then you should very shortly see that it succeeded:
GitHub app create many links in /usr/local.
Use this command to find all link files from GitHub.
ls -l $(find /usr/local -type l) | grep GitHub.app | awk '{ print $9}'
then rm them.
PS: GitHub also created some directories that cause error when run brew link git,
e.g. /usr/local/share/git-core, /usr/local/lib/perl5/site_perl.
You should remove them carefully.

override git from Xcode with homebrew version

I've installed XCode and therefore git is there as well. Since i want to have a newer version of git I installed using homebrew.
But the homebrew version of git is never called since my PATH looks like this
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
which means the /usr/bin/git is allways called before /usr/local/bin/git.
Is there a way to change that without changing the PATH?
Xcode is actually using the GIT that is stored in /Applications/Xcode.app/Contents/Developer/usr/bin. The same version of GIT gets installed in /usr/bin when you installed the command line tools as part of Xcode installation. So, you won't be able to change what Xcode is using (unless you are willing to muck with the contents of the Xcode package). If, from a terminal application, you want to use the homebrew-installed GIT then you have two options:
Reference GIT with the full path as /usr/local/bin/git ... For this case you can create an alias like alias mgit=/usr/local/bin/git and then use mgit ... from the terminal
Change the path as PATH=/usr/local/bin:$PATH either in your .bashrc or .zshrc if you use zsh file (or each time you start a terminal at the command line).
Since Xcode hard coded its own version of git which is installed on /Applications/Xcode.app/Contents/Developer/usr/bin/git, I managed to use this work around trick:
change into the Xcode directory:
cd /Applications/Xcode.app/Contents/Developer/usr/bin
rename the Xcode's git like this:
sudo mv ./git ./git-xcode-usr-bin
link my own git which is installed through homebrew:
sudo ln -s /usr/local/bin/git ./git
And I did the same thing with /usr/bin/git
This will acctually link /usr/local/Cellar/git/1.8.0/bin/git (because I'm use git 1.8.0 at the present)
Certainly this may cause some other problems, such as when I upgrade the homebrew's verion git in the future, it would not work for me :( and I have to make a new link then.
I do it like this because I want to solve my own problem here 13177203. And after search StackOverFlow for a long time, I finally got this solution.
If you are using fish shell instead of bash, you can point to your preferred git binary by adding the following to ~/.config/fish/config.fish.
function git
/usr/local/bin/git $argv;
end

Resources