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

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.

Related

Replace Xcode's git with downloaded latest 1.8.3

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

Git hanging after installing osx credential helper

I'm having the same problem as this thread: Git hangs indefinitely - broke with osx credential helper I think
Basically -- had been running git without problems, then installed the credential-osxkeychain and git began hanging indefinitely after any command. e.g., running git init results in a hanging prompt and any input creates an error: bad input
I tried following the advice to delete git from usr/bin/git but now it doesn't recognize anything. I tried reinstalling git but now it doesn't seem to recognize it.
I ran which git and it returns: /usr/local/git/bin/git
I'm somewhat new at this and don't have the balls to just start running sudo commands and moving things around in the /usr/bin directory.
Any ideas what I can do to fix this?
I had the same problem and fixed it thusly:
uninstall git via the uninstall.sh that comes with the install
reinstall git via the installer
run which git and cd to the folder containing git (eg. cd /usr/local/git/bin/)
run curl -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
run chmod u+x git-credential-osxkeychain
run git config --global credential.helper osxkeychain
Fixed.
Still not totally sure what I actually did to fix this problem, but resetting the terminal ended up getting it to work.
I had the same problem.
I didnt have git 1.7.10 or later installed. Messed everything up.
To fix, I had to delete git and install a newer version.
I used homebrew to install, after deleting.
is working again.
To fix this I reinstalled git from http://git-scm.com/download/mac
and then added /usr/local/git/bin to the top of the file /etc/paths

How to fix git config issue where all commands go to blank line?

I am not new to git but I am newer to github and still a beginner with bash. I was trying to set some config stuff and ending up breaking git on my local machine. Here's what I did following these instructions on github for password caching.
$ git config --global user.name 'myusername'
$ git config --global user.email 'myemail#email.com'
$ git credential-osxkeychain
git: 'credential-osxkeychain' is not a git command. See 'git --help'.
$ curl -s -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
$ chmod u+x git-credential-osxkeychain
$ which git
/usr/bin/git
$ sudo mv git-credential-osxkeychain /usr/bin/git
$ git config --global credential.helper osxkeychain
^?^C
After this command git I received no response, just a new line which I eventually ctrl+c'ed out of. Now, whenever I do a git command in any repo, not just this one, the cursor just moves to a new line. I'm unable to push/pull/clone or do use of the commands I normally use.
I've tried reinstalling the latest version of git and still have the problem. What should I do?
Update:
I've tried unsetting credential.helper and uninstalling and reinstalling git. Still seeing the same behavior. I noticed that if I run just $ git the response is Usage: git credential-osxkeychain <get|store|erase>. At this point, I just want to delete credential-osxkeychain. Still unsuccessful.
As requested, the output of which -a git is:
$ which -a git
/usr/bin/git
/usr/local/git/bin/git
When you ran this command:
$ sudo mv git-credential-osxkeychain /usr/bin/git
You overwrote the existing git executable with the git-credential-osxkeychain executable. That script is only meant to be run as a sub-command of Git, not standalone.
If you use Time Machine, you can try to restore the old /usr/bin/git from a backup. Otherwise, you'll need to reinstall Git.
Based on the comments below, it appears that /usr/bin/git is actually still git-credential-osxkeychain, probably because Git installed itself into /usr/local instead of /usr/bin.
If you don't care about the keychain behavior anymore, you can remove the current git executable altogether:
$ sudo rm /usr/bin/git
That may cause Git to start working for you immediately if /usr/local/git/bin is in your path. Or you could simply move it to /usr/local/git/bin/git-credential-osxkeychain:
$ sudo mv /usr/bin/git /usr/local/git/bin/git-credential-osxkeychain
which (again, assuming your path is correct) should allow you to use it as a credential helper like you originally wanted.

Trying to install git on OSX: cannont exec 'git-credential-osxkeychain': Permission denied`

I'm attempting to install Git on my new MBP and am following the documentation # https://help.github.com/articles/set-up-git.
I seem to have hit a snag at the point where it says : If you do not have the helper, you can download it and copy it to /usr/local/bin
I navigated to /usr/local/bin in terminal and did a sudo wget [link to osxkeychain]. When I try to do a git config --global credential.helper osxkeychain I get a fatal: cannont exec 'git-credential-osxkeychain': Permission denied.
What did I do wrong?
Thanks!
Tre
Download the git-credential-osxkeychain file to your desktop(!).
Open the Terminal application.
Type in the following:
sudo cp ~/Desktop/git-credential-osxkeychain /usr/local/bin/git-credential-osxkeychain
sudo chmod 755 /usr/local/bin/git-credential-osxkeychain
sudo git config --global credential.helper osxkeychain
Test it with:
sudo git credential-osxkeychain
See the sudo prefix? It seems to be required for the credential stuff... It should now output Usage: git credential-osxkeychain <get|store|erase>
Make the downloaded file executable:
chmod 755 git-credential-osxkeychain
Homebrew's git package sets this up; just:
brew install git
and you're away.
Tried sudo?
/usr/bin is protected. Or you could try downloading git executables somewhere on your laptop and add that location to your PATH.
One of the common mistakes made by people starting on git is that they have the wrong executable for the operating system.
Please make sure that when you go to git help setup page you click on the right link
for example the following link has MAC | WINDOWS | LINUX | ALL options in the top of the page which is small enough to be ignored by many.
https://help.github.com/articles/set-up-git
This has happened to many of my team member to install osx for ubuntu and end up getting the error mentioned above

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