Git version: 2.13.0.windows.1
OS: Windows 7
CLI: Git bash
.gitconfig
[user]
name = Gyandeep Singh
email = private#email.com
[push]
default = current
[core]
autocrlf = input
[includeIf "gitdir: ~/Documents/webstorm/corporate/"]
path = .gitconfig-work
.gitconfig-work
[user]
name = Gyandeep Singh
email = corporate#email.com
Both the config files above sit together in the same directory (home).
What happened: open CLI on a folder (example test) inside corporate folder and then run git config user.email the output is private#email.com.
Expected: Outcome should be corporate#email.com.
Am I doing something wrong or my expectation is not correct? I did follow the git docs.
Solution
You have to run git config --show-origin --get user.email on a git initialized directory. If its not git initialized then the includeIf gitdir functionality will not work.
Its strange but true. I wish it still worked.
Your global C:/Users/<user-name>/.gitconfig should have this includeIf:
[includeIf "gitdir:C:/Users/<user-name>/Documents/webstorm/corporate/"]
path = .gitconfig-work
with having your work Git repos in C:/Users/<user-name>/Documents/webstorm/corporate and the conditional work configuration should be located at C:/Users/<user-name>/.gitconfig-work.
That's at least working for me in Window's cmd and Cmder. A git config --show-origin --get user.email should than show you from where a config value is loaded/resolved.
It also seems like the conditional work configuration is only used when issued from within a Git repository.
C:\Users\<user-name>\Documents\webstorm\corporate
λ git config --show-origin --get user.email
file:C:/Users/<user-name>/.gitconfig foo#oss.com
C:\Users\<user-name>\Documents\webstorm\corporate\some-repo
λ git config --show-origin --get user.email
file:C:/Users/<user-name>/.gitconfig-work foo#company.com
C:\Users\<user-name>\Documents\webstorm\corporate\some-non-repo-dir
λ git config --show-origin --get user.email
file:C:/Users/<user-name>/.gitconfig foo#oss.com
You need to turn off case sensitivity: change "gitdir:" to "gitdir/i:"
[includeIf "gitdir/i:C:/Work/"]
path = .gitconfig-work
[includeIf "gitdir/i:C:/My/Dev/"]
path = .gitconfig-my
from:
https://github.com/Microsoft/vscode/issues/62921#issuecomment-437693020
The accepted answer, while helpful, does not answer the question.
As of this writing, includeIf only works inside a git initialized folder.
So if you cd into "~/Documents/webstorm/corporate/somegitproject" and run the command the output will be as expected:
$ cd ~/Documents/webstorm/corporate/somegitproject
$ git config user.email
corporate#email.com
This is probably a defect against git, since a user would expect this to work similarly in "~/Documents/webstorm/corporate/" as well.
There is a typo here:
[includeIf "gitdir: ~/Documents/webstorm/corporate/"]
path = .gitconfig-work
There should be no space after gitdir::
[includeIf "gitdir:~/Documents/webstorm/corporate/"]
path = .gitconfig-work
Removing it will correct the behavior within an initialized Git repository.
This will show the entire Git configuration and what Git config files it is drawn from:
git config --list --show-origin
CAVEAT: If you run this inside a Git repository it will show values from .gitconfig-work, but it will not if you are within ~/Documents/webstorm/corporate/, but outside a Git repository.
The OP concludes that includeIf functionality does not work in normal non-git directories.
This is provably incorrect for at least the configuration item core.sshCommand. If a conditionally included .gitconfig has a core.sshCommand configured, it is used in git clone operations in normal non-git directories.
It seems that the part that doesn't work properly is the display of conditionally included configuration. Which is quite problematic and interferes with tracking down broken configurations.
I mapped a directory to a drive on a windows machine with subst D: <mapped directory>. If you want to know the path of your repository you can use this command in the repository context:
git rev-parse --show-toplevel
The output was something like this:
<mapped directory>/<name of repository>
So I changed it to:
[includeIf "gitdir:<mapped directory>/"]
path = .gitconfig-work
Now it works for me.
Related
I'm new to git, and i'm trying to install git 2.9.2 from here. In the installation (the last of the many) i chose to run it from bash only. I now try to set it up, and the first thing i try is to set my name with
$ git config --global user.name "My Name"
But after i execute this, i get:
fatal: unable to access 'C:\Program Files\Git\ C:\Windows\system32\config\systemprofile/.config/git/config': Invalid argument
Let's say that i now want to clone a repository. I insert something like:
git clone https://username#bitbucket.org/team/repo.git
But i get:
fatal: unable to access 'D:\TestRepo\ C:\Users\username/.config/git/config': Invalid argument
I thought that the .gitconfig file should be inside the C:/Users/username directory, but it tries to locate C:\Users\username/.config/git/config, which seems a little weird. My HOME variable is %USERPROFILE%, as it should. Any help appreciated.
Ok i guess my lack of knowledge over basic things made me look stupid...
I just had to delete the HOME environmental variable and all worked like charm. I don't even remember why i had a HOME variable set (isn't that a linux thing?)
Anyway thank you for your time guys.
Did you use git init on the folder you are trying to operate from?
Also you need to configure your username and the email to your github account for it to work properly.
git config --global user.name "username"
git config --global user.email "email#gmail.com"
Finally, if you have a space in your name please remember to escape it. ex: "my name" = "my\ name"
did you set up your remote repository?
git remote add origin https://github.com/rodoggx/yourRepository.git
Same issue. But if I run with command shell (not bash) with Admin level, git config --global -l works. My git version 2.25.0.windows.1
I noticed that in the System Info gui of Windows, the env variables for System had a HOME entry of %USERPROFILE%. But, the User env variables did not. I added HOME to that too.
Now it works. You'd think the System env would fill in for those not in User. Maybe something else is going on.
I have a chef recipe that goes to github and clones a repo. Unfortunately, I dont have git configured to use the certs and hence it has issues using https protocol with github.com.
My temp solution is to run the following and dont check for ssl.
git config --global http.sslVerify false
This works when I do it manually so I put it in a bash block :
bash 'SSLVerify=False' do
user 'root'
cwd '/home'
code <<-EOH
git config --global http.sslVerify false
echo "SSL Check Disabled for git"
EOH
end
This succeeds and gives me the echo, but as the chef recipe comes to github clone part it fails again. Is the scope or bash only for the code in it or globally ?
The 'git config' command updates the .gitconfig file which would be in the home directory of the user executing the git config command. I would suggest you to have a look into the config file if it is updated or not. It should have following entry
[http]
sslVerify = false
If you see this entry then you would need to verify that the git clone is using the same config.
Add environment 'HOME' => '/root' to the resource. A lot of programs don't actually check the homedir of the user and assume $HOME is set.
when I try to config Git I receive the following error:
$ git config --global user.name "John Smith"
error: could not lock config file /Users/John/.gitconfig: No such file or directory
My root directory is completely missing a .gitconfig file. When I try to make a new one I receive this error:
$ touch ~/.gitconfig
touch: /Users/John/.gitconfig: No such file or directory
My git's location:
$ which git
/usr/local/git/bin/git
I've tried reinstalling Git several times (running OSX Yosemite) and I'm still having the same issue. I also cannot locate any .gitconfig.lock files, as mentioned in some posts regarding this issue.
So I ended up solving this issue by reading the Customizing Git section of the documentation.
While I could not touch a new .gitconfig file in my root directory as stated above, I read that the first place Git looks for configuration values is in etc/gitconfig (note the lack of a . in the name).
So I created a file called gitconfig inside of the etc directory and filled it in with a sample gitconfig I found online, and added my user information to the top like so:
[user]
name = John Smith
email = jsmith#example.com
I was then able to commit as my usual self, however I still don't have a .gitconfig in my root, so I am unable to config Git using git config --global, and must do the configurations manually in etc/gitconfig.
For me the .gitconfig file was missing.I tried reinstalling Git several times, however it din't help me. I resolved the issue by performing the below steps.
create a folder structure c:/dev/home if already not present.
Open the Windows command prompt. (Run as administrator)
From the Windows command prompt, run the command "git init"
Run the following command:
git config --global user.name "Example"
Run the following command:
git config --global user.email "Example#gmail.com"
The above steps will create the .gitconfig file in the path c:/dev/home and you will be able to set your desired username and email id.
On Windows systems, Git looks for the .gitconfig file in the $HOME directory (C:\Users\$USER for most people). So copy the file created in the above step to your Home directory by providing the required permission.
I solved that. By adding .gitconfig file to the Home directory. Now it works fine.
I was changing the default merge tool of git, and an error occurred with my configuration, now my git doesn't work.
Is possible come back to the default configuration?
Thanks
In addition to Alan Haggai Alavi's answers, which is inclusive of the following, if you are confident that changing the merge tool was the problem, you can just revert your merge tool changes:
git config --global --unset merge.tool
git config --unset merge.tool
Review Git configuration files:
Global user configuration file: ~/.gitconfig
Repository configuration file: .git/config
i am working with an other developer in developing an iOS application and now he don't work with us and i am working with his computer but the problem is when i push my code i am seeing his name appearing in the github. how i can change this and put my name appearing in the github. thanks for your answers.
Do you have a .gitconfig file in your project directory, if so, cd into the project directory and run the following commands to set it to your name and email in the .gitconfig file of your project
git config user.name "Your Name"
git config user.email "your-email-address#email.com"
If you do not have a .gitconfig file in your project directory, it could be using the global .gitconfig file located in the Home directory (~/). Simply add the --global flag to set it on a global basis for all projects (note, if there is a .gitconfig file within the project directory, it will use that rather than the global .gitconfig in the home directory)
git config --global user.name "Your name"
git config --global user.email "your-email-address#email.com"