Question

I would like to know, since I've been looking quite some time on how to do this, atleast in this community. would like to know how to change the $HOME directory in a Mac OS X Lion, in Git.

In other words, how do I make it so that my global user settings are saved in a folder like git and not right inside the main user folder? Or is it already like that? I basically want to keep a centralized place for all my files and stuff that I use in Git (for example, a .gitmessage.txt file, if I'm not mistaken, this shouldn't be hidden since it's a TXT file).

If you need more info don't hesitate to ask.

Was it helpful?

Solution

Read git config manual, it says about GIT_CONFIG environment variable.

OTHER TIPS

If you want to use an alternative .gitconfig file you can only do so by changing the $HOME variable for the current shell and it's children.

Contrary to what other replies have indicated - Git will always read the file located at $HOME/.gitconfig - regardless of what how you set GIT_CONFIG.

The documentation has been incorrect since 2011 and remains incorrect, GIT_CONFIG is ignored.

More details as to why it is ignored can be found within this git mailing list thread.

Changing the location of your home directory is possible by redefining the HOME variable, you can do so with the following (Bash) snippet:

export HOME=<directory containing your alternate .gitconfig file)

Doing so will not be entirely painless, various things will be messed up, such as shell initialization files, editor configuration and history files, the shell history file, etc..

If you can cope with the aforementioned limitations, that may be an acceptable solution.

As of 29th Sept 2016 - a patch has been submitted by Junio C Hamano (Git maintainer) which will allow overriding the global /etc/gitconfig file via a new variable : GIT_CONFIG_SYSTEM_PATH - this patch is not yet integrated into a git release, expect it to hit mainstream Linux distributions around 2018/2019 if accepted.

I find that building software within docker containers and supplying a .gitconfig file is an approach that works reasonably well (in the absence of a better solution) but this may not be to everyone's taste and could be more complex than necessary.

Ok, here's how I do this...it's very simple.

First, type "cd ~" when git first loads ( this takes you to root directory)

Second, type "cd path/path/path" (the path to the directory you want as home directory)

Third, once you are in your desired directory...
type "alias home="path/path/path"(the directory you desire)

Now every time Git loads, all you have to do is type "home", as this is the alias "home" which will enter the path to the directory that you want to work from. You must remember to type "cd ~" when Git first loads to get you to the root directory...then this alias will work, otherwise it will not recognise the path from another directory.

This is the easiest and a sure way to do this regardless of inherent of code problems. Just make the alias, and then "cd ~" when Git loads to make sure you are in the root directory. Every time Git loads, you will type "cd ~", and then "home". That's the easiest way I've found... Hope that helps.

It's also nice if you're going to be working in multiple directories, as you can just make different alias's for each path/path/path/path, and it will save you time bouncing around, you'll just need to "cd ~" to get to the root, and then type your chosen alias.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top