Replace Xcode's git with downloaded latest 1.8.3 - xcode

I want to use latest version of git (1.8.3).
Currently when I make git --version it shows me git version 1.7.12.4 (Apple Git-37) which was installed together with Xcode I suppose.
I installed newest version but still bash uses Xcode one..
Please advice me how to override xcode git with the path that is installed to usr/local/bin?
Thanks!

Edit ~/.bash_profile and add
alias git=/usr/local/bin/git
Source the bash_profile file or restart bash (source ~/.bash_profile)
See what git --version prints.
I am not sure if this affects XCode. I never use versioning tools in IDEs, I do it from the command line
Or you add /usr/local/bin to $PATH to your bash_profile. I do this with macports or better said macports alters your bash_profile automatically.
export PATH=/usr/local/bin:$PATH

Use a symbolic link to make Xcode use the /usr/local/bin/git instead of its built-in git
cd /Applications/Xcode.app/Contents/Developer/usr/bin/
sudo mv git xcodeGIt
sudo ln -s git /usr/local/git
Disclaimer: typed inline -- but thats how it works. Done it and it works fine for me

Related

Updated Git but still showing old version

I downloaded and installed Git 1.8.4.2 from this link: http://git-scm.com/downloads. However, when I run git --version from the Terminal I get:
[~/workspace/ruby]: git --version
git version 1.7.4.4
I've tried restarting the terminal and my computer. I then tried using the info at https://code.google.com/p/git-osx-installer/wiki/Uninstall. I did the following in the terminal from within /usr:
sudo rm -rf /usr/local/git
sudo rm /etc/paths.d/git
sudo rm /etc/manpaths.d/git
I then ran the new git .dmg file again but am still getting 1.7.4.4 when I run git --version. I suppose there's something going on here with the Mac filesystem that I don't understand. Any help would be greatly appreciated!
Run the command:
which git
You'll probably see /usr/bin/git -- the Apple supplied version. This will be because /usr/bin appears in your PATH environment variable before /usr/local/git/bin. You can verify this by running the command:
echo $PATH
If that is the case then run this command:
export PATH=/usr/local/git/bin:$PATH
and then try git --version again. You should now get 1.8.4.2. This hasn't fixed it permanently yet though. You'll need to add the export PATH=... line to your ~/.bashrc so that it gets set for every shell.

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.

Accidentally delete /usr/bin/git file and now I cannot work with git on the terminal

I had a problem with git on my machine and I accidentally deleted the /usr/bin/git from my system.
My git was installed through the XCode Command Line Tools and I cannot find a way to reinstall it.
The git was not uninstalled, the git file was removed.
Is there a way from XCode or somewhere else to reinstall the command line tools? or somewhere Where I can get the original git file to add to /usr/bin again?
THanks
sudo cp /Applications/Xcode.app/Contents/Developer/usr/bin/git /usr/bin/git
I don't know why /usr/bin/git isn't just a symlink to that file, but on my system it's a separate (identical) copy.

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