System level git config in mac - macos

I am able to see global and local config files at usual locations.
But if i type
git config --system --list
it gives me
fatal: unable to read config file '/Library/Developer/CommandLineTools/usr/etc/gitconfig': No such file or directory
Any idea why it is looking there?
And why it is not set? Where is
system git config location for Mac?
There is no file at /etc/gitconfig or $HOME/.config/git (prescribed location got *nix and osx respectively)
EDIT
doing
sudo git config --system --list
does not help

#Abhijit Mazumder:
I know this is an old question, but I had a similar issue when attempting to set a system level git config value on my mac and thought I would post my solution here in case it could help you.
NOTE: I strongly suspect that if you simply create the
'/Library/Developer/CommandLineTools/usr/etc/' directory and create a
file called gitconfig within that directory, then your attempts at
viewing or setting system level git config values will be successful.
My first attempt at setting a system level git config value on my mac was:
git config --system alias.cl clone
This resulted in an error:
error: could not lock config file /Applications/Xcode.app/Contents/Developer/usr/etc/gitconfig: No such file or directory
I thought perhaps I needed to add 'sudo' to the command:
sudo git config --system alias.cl clone
But running the command with 'sudo' gave me the same error:
error: could not lock config file /Applications/Xcode.app/Contents/Developer/usr/etc/gitconfig: No such file or directory
So, from the root directory on my mac, I switched into the 'usr' directory mentioned in the error, just to see what was in there:
cd Applications/Xcode.app/Contents/Developer/usr/
I was surprised to find that there was no 'etc' directory. The only directories I saw were 'bin', 'lib', 'libexec', and 'share'.
So I decided to create what was missing. I first created an 'etc' directory:
sudo mkdir etc
And then created a gitconfig file in the 'etc' directory:
sudo touch etc/gitconfig
I was then able to set a system level git config value with the following command:
sudo git config --system alias.cl clone
In order to confirm that the system level git config value had actually been set, I viewed the contents of the gitconfig file.
I first used the unix 'cat' command while inside my 'usr' directory:
cat etc/gitconfig
The output from the 'cat' command was:
[alias]
cl = clone
Then I used a git command (the same one you were trying to use in your question) to check that my system level git config value had been set:
git config --system --list
The output from this command was:
alias.cl=clone
The last thing I needed to do to ensure that I had placed my file in the proper location was try the alias I had created, so I tried running:
git cl
Running this command using the alias I created resulted in the following output, which confirmed for me that everything was working properly:
You must specify a repository to clone.
usage: git clone [<options>] [--] <repo> [<dir>]
-v, --verbose be more verbose
-q, --quiet be more quiet
--progress force progress reporting
-n, --no-checkout don't create a checkout
--bare create a bare repository
--mirror create a mirror repository (implies bare)
-l, --local to clone from a local repository
--no-hardlinks don't use local hardlinks, always copy
-s, --shared setup as shared repository
--recursive initialize submodules in the clone
--recurse-submodules initialize submodules in the clone
--template <template-directory>
directory from which templates will be used
--reference <repo> reference repository
--dissociate use --reference only while cloning
-o, --origin <name> use <name> instead of 'origin' to track upstream
-b, --branch <branch>
checkout <branch> instead of the remote's HEAD
-u, --upload-pack <path>
path to git-upload-pack on the remote
--depth <depth> create a shallow clone of that depth
--single-branch clone only one branch, HEAD or --branch
--separate-git-dir <gitdir>
separate git dir from working tree
-c, --config <key=value>
set config inside the new repository

I have not come across this error as my machines are only used by me so setting --global level is enough, however that location looks reasonable (I assume you are using the git supplied with the Xcode command line tools).
Using sudo to configure what you want should work:
$ sudo git config --system <name> <value>

Related

How to deal: not a git repository: '/home/user/git' even if it is

Some time ago i created a 'git' directory in a home path, just to store repos i use. But this somehow broke all my git system and even in ~ folder, when i was trying to use git, i was outputting me this (PWD=/home/user):
$ git status
fatal: This operation must be run in a work tree
I've removed 'git' folder, but appear another problem (PWD=/home/user):
$ git status
fatal: not a git repository: '/home/user/git'
I tried to reinstall git. Not helped. I'm a bit confused about this.
UPD #1:
I'm sorry for bad explanation at the beginning.
This should be clear enough:
$pwd
/home/user/MyGitRepos/some_repo/
$ls -a
. .. .git README.md
$git status
fatal: not a git repository: '/home/user/git'
Any path i am /, /etc, /home/user/ gives me the same output:
fatal: not a git repository: '/home/user/git'
Double-check your environment variables.
If you have GIT_DIR or GIT_WORK_TREE set to /home/user/git, that would explain the error message.
Check also git config -l --show-scope --show-origin in case any configuration would also reference that path.

Git clone on windows : git#github.com is not a git command

I'm trying to clone a repository the ssh way from github and another form gitlab
I'm on windows EDIT : with Git v 2.29.2.2
I'm getting the following error, which I do not understand from what it is coming from :
$ git clone git#github.com:math-gallou/AI21_TPs.git
Cloning into 'AI21_TPs'...
git: 'git#github.com' is not a git command. See 'git --help'.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
So I also tried :
$ git clone "ssh://git#github.com:math-gallou/AI21_TPs.git"
and
$ git clone ssh://git#github.com:math-gallou/AI21_TPs.git
But the same exact error comes out.
When I do the ssh -v git#github.com I can connect with success.
So what did I miss ?
First, if you are trying the ssh:// syntax, then the URL would be:
git clone ssh://git#github.com/math-gallou/AI21_TPs.git
^^^ /, not :
Second, check if you have a %USERPROFILE%\.ssh\config file with a github.com Host entry in it, whose content might be incorrect or mis-interpreted.
In my case, I defined system environment variable GIT_SSH to use openssh I installed, and then git is broken and I got git: 'git#github.com' is not a git command. See 'git --help'..
After deleting system environment variable GIT_SSH everything works again.
Then I tried to define user environment variable GIT_SSH and restart system (I didn't restart system in previous try), somehow now my git works correctly with openssh I installed. I don't know which part is wrong in my previous try but I decide not to waste more time on this.

Why does my git bash always start at master branch?

I have a Windows PC with git installed. Whenever I start git bash, it always stand at /c/Users/_user with master branch as below:
NativeKiwi#nkiwi MINGW64 ~ (master)
I think it should look like this:
NativeKiwi#nkiwi MINGW64 ~
I had a look at people around, found out that they don't have (master) at their first start using git bash. I checked git repo at where I stand with git remote -v but there is nothing.
The string shown in your prompt depends on your PS1 environment variable.
Please check your .bash_profile or .bashrc for the configuration of PS1 environment variable.
I had the same issue (due to running git init) in the wrong directory and fixed it by running rm -rf .git in that directory.
You are seeing master because you created a git repository at the current path using the git init command. Always create git repositories in the folders containing project files. Consider running rm -rf .git command.

Can't commit update-index on Windows

I have a executable file called post_deploy that's run on my OpenShift gear after a push, but it wasn't executable so I ran:
git update-index --chmod=+x .openshift/action_hooks/post_deploy
But every time I did a git add to commit the file, the file would loose the executable permission. If I tried to do a commit, git would tell me there was nothing to commit. I eventually had to pop over to Cygwin to get it to work, but how can I get this to work in Window's Command Prompt?
Check your Git version: with Git 2.9.1, you can add with chmod
git add --chmod=+x -- yourFile
Also check the value of git config core.filemode. I suspect it should be false (which is expected in an environment which does not support executable bit).
Still, the add --chmod=+x should be enough to record that executable bit in the Git repo.
Finally, clone your repo in a Linux/Cygwin environment and check if the file is not already executable there.
The OP NicholasJohn16 reports below using "How do I remove files saying “old mode 100755 new mode 100644” from unstaged changes in Git?" to solve the issue.

`git add` doesn't add files to track on Windows

I have a local folder which I wanted to convert to a Git repository and then push to a remote repository. I ran the command git init in the project folder and then used the command git add .. When I run the command git status, I get the message that I have untracked files. I ran the git add . command multiple times but I see the same message.
What should I do to track these files so I can push to a remote repo?
I'm using Windows 8.1 x64 machine.
UPDATE: Please see the answer below.
I used the command git config --system core.longpaths true to fix the error for longer file names. I was able to add all files after making that change.

Resources