I am running this command under windows 7:
git status
Now I am getting this error:
fatal: unable to access 'H:\/.config/git/config
I am disconnected from the network at the moment. Can I still fix this by changing the config location or creating a new config?
Can I still fix this by changing the config location or creating a new config?
You can simply change your environment variable HOME, in order to reference an existing local folder
set HOME=C:\local\path
In that folder, a .gitconfig can be defined in order to have a global git config file.
The msysgit/msysgit/git-cmd.bat defines it by default to:
#if not exist "%HOME%" #set HOME=%USERPROFILE%
Git will respect the HOME environment variable to determine the location of the global .gitconfig.
If asking your domain admin to reset your HOMEDRIVE and HOMEPATH variable back to your local user profile is not an option, you can simply change the HOME variable instead (which is usually unset, so there won’t be a conflict) at the top of your shell to make Git use that location.
For example, if you’re using Git Bash, you can simply add the following line to the bottom of your shell profile, located at C:\Program Files (x86)\Git\etc\profile:
export HOME="$USERPROFILE"
(I think $USERPROFILE is still left to the default even if the domain settings change your home drive. Of course, you can always specify a fixed path if that doesn’t work)
If you are using other shells, you can do similar things, for example in PowerShell:
$env:HOME = $env:USERPROFILE # or = 'C:\Users\poke\'
Of course, since the variable is unset by default, you could also set it at Windows level in your system configuration. That way, every program would use it automatically.
Afterwards, all Git commands will automatically look at $HOME\.gitconfig.
You need to specify the config file location using git config and the -f option.
git config -f your_config_file
Related
I must put all the files GO creates inside the structure of GO, not scattered. While changing GOPATH and GOROOT, I noticed the build folder on ~/.cache/go-build.
This SO thread didn't help at all, not either the article it links. It doesn't seems to deal directly with that. How can I change it?
Edit: the problem isn't how to find the GOCACHE, which I already know that can be viewed by go env GOCACHE, but how can I change that folder.
I've tried to add to ~/ .bashrc:
export GOCACHE=$HOME/path/to/folder, and now when I use go env GOCACHE, it points to the new folder but still tries to send files to ~/.cache/go-build. The log file is now returning the following error:
go: disabling cache (/home/<me>/.cache/go-build) due to initialization failure: mkdir /home/<me>/.cache/go-build: permission denied
The error shown
go: disabling cache (/home/<me>/.cache/go-build) due to initialization failure: mkdir /home/<me>/.cache/go-build: permission denied
Is because the directory /home/<me>/.cache/go-build does not exist and permissions to create a new directory aren't there. This shouldn't happen, it seems like some unknown factor in your build process is clobbering the GOCACHE settings
Do you literally have a user called <me>? That's quite unusual and ill advised, as <> are shell meta characters
As for setting the path, see https://github.com/golang/go/blob/master/src/cmd/go/internal/cache/default.go
and https://golang.org/pkg/os/#UserCacheDir
If GOCACHE env variable is set then it uses that. If not it uses os.UserCacheDir which is usually $HOME/.cache but can be overridden, see the docs
The simple answer is to set the GOCACHE env variable to be inside your Go containment area
Just to clarify. Go compiler and tools run inside another environment.
This other environment has variables set inside it, which Go will honour
On Linux systems, this environment is usually the bash shell. In the bash shell to set the GOPATH the command "export GOPATH=$HOME/go" is often used, to set up a GOPATH to a folder called go in the home directory of the current user. To set the GOCACHE set the variable in the environment you are using and Go will pick it up
cd $HOME
sudo chown -R <yourname>.<yourname> .cache/go-build
It works for me.
I was having the same issue, using a Mac.
I solved it by unlocking the folder, see prints below
The first one is a sign in Finder showing the folder is locked
And the second is where to unlock folder
Using z in zsh, I want to change the default location of where the history is kept.
By default, when your source the shell script
source ~/z/z.sh
It will make a file with the directories you visit in a .z/ directory. While this is fine for most cases, I want to change this to another directory. The README.md does state that you can set some variables for this in my .zshrc
Optionally:
Set $_Z_DATA to change the datafile (default $HOME/.z).
So I added this
export $_Z_DATA="$HOME/.z-history"
But for some reason, I get a warning that my shell can't find the directory.
Any idea why this is happening? Any help is appreciated.
You are having a typo, or haven't yet get how the bash variable works.
You do not need to use $ when declaring a variable. Only when you want to access it.
So just adapt you config with:
export _Z_DATA="$HOME/.z-history"
voilà :) it should works
I have tortoiseSVN installed alongside subversion for windows (not using TortoiseSVN command client tools because of restrictive purposes).
I have a batch file that runs an svn update on certain folders which are used as environmental variables in Windows. Is it possible to svn update a folder using just the folder name?
e.g. from this:
cd C:\foo\johnsmith\testing\
svn update
to something like this?
cd testing\
svn update
I should add that environmental variables are new to me...
With regards to Alrocs comment, the path C:\foo\johnsmith\testing\ is in the system environmental variable "Path".
You can't cd to directory, which is part of your $PATH$. But you can use environment variable, which explicitly contain needed path only (after all - variable is just string)
c:\TEMP>echo "%USERPROFILE%"
"C:\Documents and Settings\Badger"
c:\TEMP>cd "%USERPROFILE%"
C:\Documents and Settings\Badger>
Never assume anything about environment variables that you haven't set via your batch file. Just because it's there today/on your computer doesn't necessarily mean it'll be there tomorrow or on another computer.
But you aren't using an environment variable in your script in the first place.
If you need to update a specific path, be explicit and update that path by specifying the whole path. Don't assume that your testing directory will be an immediate child of the directory you're running the batch file in unless you can control everything else - the whole subdirectory structure, where the batch file executes from, and how it executes.
I've the problem that my home directory is actually located on a remote server and with ~/.vagrant.d sitting on that server, the performance of vagrant decreases heavily (and file-server backup size increases).
So is there any way to move at least ~/vagrant.d/boxes out of the home directory?
Cheers.
By default Vagrant uses ~/.vagrant.d. Fortunately, vagrant provides an environment variable called VAGRANT_HOME by which you can set vagrant home.
Just do the following to change the vagrant home (this only works in the current session)
export VAGRANT_HOME=/path/to/vagrant
To make it permanent, add this to your ~/.bash_profile (for login shell).
Update: VAGRANT_HOME has been added to the documentation - Environmental Variables
VAGRANT_HOME can be set to change the directory where Vagrant stores global state. By default, this is set to ~/.vagrant.d. The Vagrant home directory is where things such as boxes are stored, so it can actually become quite large on disk.
VAGRANT_HOME does not work well in my Windows 8.1. It worked for me when I changed the file
D:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.5.3\lib\vagrant\environment.rb
on line 117 to
#home_path = Util::Platform.fs_real_path("D:/vagrant/home/")
like Steve H said and it works fine.
It might be useful to permanently set this on a Windows box by executing
setx VAGRANT_HOME "/d/.vagrant.d/"
On Windows change line 17 of environment.rb located at:
vagrant\embedded\gems\gems\vagrant-1.x.x.dev\lib\vagrant\environment.rb
an other place (the root place where it read ENV variables) is in shared_helpers.rb, line 71 (vagrant v 1.6.5) :
# This returns the path to the ~/.vagrant.d folder where Vagrant's
# per-user state is stored.
#
# #return [Pathname]
def self.user_data_path
# Use user spcified env var if available
path = ENV["VAGRANT_HOME"]
# On Windows, we default to the USERPROFILE directory if it
# is available. This is more compatible with Cygwin and sharing
# the home directory across shells.
if !path && ENV["USERPROFILE"]
path = "#{ENV["USERPROFILE"]}/.vagrant.d"
end
# Fallback to the default
path ||= "~/.vagrant.d"
Pathname.new(path).expand_path
end
Anyway, I think the best way is to use the environment variable VAGRANT_HOME, in case of vagrant version upgrade.
You can use this function like:
disk_path = self.user_data_path().to_s
For Windows users, set the environment variable VAGRANT_HOME to the new location. You might need to restart your PC for it to take effect.
It works for me on Linux creating a simbolic link from a folder on my secundary hard drive to ~/.vagrant.d/boxes/.
Set of VAGRANT_DOTFILE_PATH environmental variable helped me on Windows machine. VAGRANT_HOME didn't work out.
By default on Windows Git places global .gitconfig in c:\documents and settings\user\
How can I change that position so .gitconfig is stored in c:\my_configuration_files\?
Can it be done at all?
If you set HOME to c:\my_configuration_files\, then git will locate .gitconfig there. Editing environment variables is described here. You need to set the HOME variable, then re-open any cmd.exe window. Use the "set" command to verify that HOME indeed points to the right value.
Changing HOME will, of course, also affect other applications. However, from reading git's source code, that appears to be the only way to change the location of these files without the need to adjust the command line. You should also consider Stefan's response: you can set the GIT_CONFIG variable. However, to give it the effect you desire, you need to pass the --global flag to all git invocations (plus any local .git/config files are ignored).
Change HOME directory for this is wrong. Better is create symbolic link for gitconfig to HOME directory.
Move your .gitconfig from user home directory, to the directory where you want.
Run command line as Administrator
Go to your user home directory
Enter mklink .gitconfig \PathForNewLocationOfConfig.gitconfig
I have solved this problem using a slightly different approach that I have seen work for other configuration files. Git Config supports includes that allows you to point to a configuration file in another location. That alternate location is then imported and expanded in place as if it was part of .gitconfig file. So now I just have a single entry in .gitconfig:
[include]
path = c:\\path\\to\\my.config
Any updates written by Git to the .gitconfig file will not overwrite my include path. It does mean that occasionally I may need to move values from .gitconfig to my.config.
Look in the FILES and ENVIRONMENT section of git help config.
I'm no Git master, but from searching around the solution that worked easiest for me was to just go to C:\Program Files (x86)\Git\etc and open profile in a text editor.
There's an if statement on line 37 # Set up USER's home directory. I took out the if statement and put in the local directory that I wanted the gitconfig to be, then I just copied my existing gitconfig file (was on a network drive) to that location.
As of at least 2.34.1, you can now set GIT_CONFIG_GLOBAL environment variable to a path to your .gitconfig file. See http://git-scm.com/docs/git-config#_environment for more details.
For me, changing the Start In location (of git-gui at least) did not affect where it looked for .gitconfig. My setup at work mounts U: for our home, but we do not have permission to write in U: directly, only subdirectories which were created for us inside, so this was a deal-breaker for me.
I solved the problem by making a batch script which would override the HOMEDRIVE and HOMEPATH env variables just for that application. Then changed my Start menu shortcut to point to that batch script instead.
First check HOME setting, then change HOME and HOMEDRIVE to a existing dir.
c:\git>set HOME
HOME=U:\
HOMEDRIVE=U:
HOMEPATH=\
then change HOME and HOMEDRIVE by
set HOME=c:\tmp
set HOMEDRIVE=C:
Change to folder %PROGRAMFILES%\Git\etc
Edit file profile
Add to first line HOME="c:\location_were_you_want_gitconfig"
Done
Note: The file permissions are usually restricted, so change them accordingly or you won't be able to save your changes.
If you are on windows and having problem either changing environment variables or mklink because of insufficient privileges, an easy solution to your problem is to start git batch in another location.
Just right click on Git Bash.exe, click properties and change the "Start in" property to c:\my_configuration_files\.
I wanted to do the same thing. The best I could find was #MicTech's solution. However, as pointed out by #MotoWilliams this does not survive any updates made by Git to the .gitconfig file which replaces the link with a new file containing only the new settings.
I solved this by writing the following PowerShell script and running it in my profile startup script. Each time it is run it copies any settings that have been added to the user's .gitconfig to the global one and then replaces all the text in the .gitconfig file with and [include] header that imports the global file.
I keep the global .gitconfig file in a repo along with a lot of other global scripts and tools. All I have to do is remember to check in any changes that the script appends to my global file.
This seems to work pretty transparently for me. Hope it helps!
Sept 9th: Updated to detect when new entries added to the config file are duplicates and ignore them. This is useful for tools like SourceTree which will write new updates if they cannot find existing ones and do not follow includes.
function git-config-update
{
$localPath = "$env:USERPROFILE\.gitconfig".replace('\', "\\")
$globalPath = "C:\src\github\Global\Git\gitconfig".replace('\', "\\")
$redirectAutoText = "# Generated file. Do not edit!`n[include]`n path = $globalPath`n`n"
$localText = get-content $localPath
$diffs = (compare-object -ref $redirectAutoText.split("`n") -diff ($localText) |
measure-object).count
if ($diffs -eq 0)
{
write-output ".gitconfig unchanged."
return
}
$skipLines = 0
$diffs = (compare-object -ref ($redirectAutoText.split("`n") |
select -f 3) -diff ($localText | select -f 3) | measure-object).count
if ($diffs -eq 0)
{
$skipLines = 4
write-warning "New settings appended to $localPath...`n "
}
else
{
write-warning "New settings found in $localPath...`n "
}
$localLines = (get-content $localPath | select -Skip $skipLines) -join "`n"
$newSettings = $localLines.Split(#("["), [StringSplitOptions]::RemoveEmptyEntries) |
where { ![String]::IsNullOrWhiteSpace($_) } | %{ "[$_".TrimEnd() }
$globalLines = (get-content $globalPath) -join "`n"
$globalSettings = $globalLines.Split(#("["), [StringSplitOptions]::RemoveEmptyEntries)|
where { ![String]::IsNullOrWhiteSpace($_) } | %{ "[$_".TrimEnd() }
$appendSettings = ($newSettings | %{ $_.Trim() } |
where { !($globalSettings -contains $_.Trim()) })
if ([string]::IsNullOrWhitespace($appendSettings))
{
write-output "No new settings found."
}
else
{
echo $appendSettings
add-content $globalPath ("`n# Additional settings added from $env:COMPUTERNAME on " + (Get-Date -displayhint date) + "`n" + $appendSettings)
}
set-content $localPath $redirectAutoText -force
}
As someone who has been interested in this for a VERY LONG TIME. See from the manual:
$XDG_CONFIG_HOME/git/config - Second user-specific configuration file. If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used. Any single-valued variable set in this file will be overwritten by whatever is in ~/.gitconfig. It is a good idea not to create this file if you sometimes use older versions of Git, as support for this file was added fairly recently.
Which was only recently added. This dump is from 2.15.0.
Works for me.
For me it worked very simple:
Copy ".gitconfig" from old directory: to %USERPROFILE% (standard in "c:\users\username")
Right click on start-icons of GITGUI and GITBASH and change "run in": "%HOMEDRIVE%%HOMEPATH%" to "%USERPROFILE%". Of cource you can use any other directory instead of "%USERPROFILE%".
screen shot before
screen shot after
Solution without having to change Windows HOME variable
OS: Windows 10
git version: 2.27.0.windows.1
I use portable version of Git, so all my config files are on my pen-drive(E:). This is what worked for me:
Download portable Git from https://git-scm.com/. Run the file and install it in the required location. I installed it in E:\git.
Run git-bash.exe from E:\git.
I wanted to put .gitconfig and other bash files in E, so I created a folder called home where I want them all in.
mkdir home
Go to etc folder and open the file called profile (In my case, it's E:\git\etc\profile)
Add absolute path to the home directory we created (or to the directory where you want to have your .gitconfig file located) at the end of the profile file.
HOME="E:\git\home"
Now it no longer searches in the C:\Users<username> directory for .gitconfig but only looks in your set path above.
$ git config --global --list
fatal: unable to read config file 'E:/git/home/.gitconfig': No such file or directory
It gave an error because there isn't a .gitconfig file there yet. This is just to demonstrate that we have successfully changed the location of the .gitconfig file without changing the HOME directory in Windows.
1- open D:\PortableApps\Git-2.31.1PortableByAmir\etc\profile bye notepad
2- add this to profile file:
HOME="/PortableHome"
3- create PortableHome folder in D:\PortableApps\Git-2.31.1PortableByAmir\
4- copy
C:\Users\Amir\.gitconfig
C:\Users\Amir\.git-credentials
to
D:\PortableApps\Git-2.31.1PortableByAmir\PortableHome
Note: D:\PortableApps\Git-2.31.1PortableByAmir\bin\bash.exe is not a portable git
only open D:\PortableApps\Git-2.31.1PortableByAmir\git-bash.exe