3

3Installing Git

3.3

Changing the Git default locations

Back to the in­tu­itive easy to learn Git Bash.

By de­fault Git wants to use your user di­rec­tory as its home di­rec­tory. This is where it wants to put all its con­fig­u­ra­tion files and repos­i­to­ries; it is the de­fault lo­ca­tion that is opened when you start Git Bash.

On my sys­tem it’s here:

C:\Users\Michael Gled­hill\

Now I don’t want to use my user di­rec­tory as the main lo­ca­tion for Git, I want to use a spe­cial folder that I’ve set up to hold the Git repos­i­to­ries (Git repos­i­to­ries are where we store a soft­ware pro­ject). I ac­tu­ally want it to use this lo­ca­tion:

D:\2500 Git Pro­jects

This is just a local folder on my D drive (see § 2.2.1).

Each repos­i­tory will be a sub di­rec­tory of this par­ent di­rec­tory (2500 Git Pro­jects).

If your per­fectly happy using your user di­rec­tory as the de­fault di­rec­tory for Git, you can skip the next bit.

3.3.1

Changing the default directories

There’s two parts to this:

  1. Changing Git so it stores its configuration files in the new location

  2. Changing Git so it starts in the new location

Tak­ing these in turn:

Changing where Git and Git Bash store the configuration files

Git has sev­eral con­fig­u­ra­tion files:

It has a mas­ter con­fig­u­ra­tion file called git­con­fig. On a Win­dows ma­chine it lives here:

C:\Pro­gram Files\Git\ming­w64\etc\git­con­fig

This is some­times re­ferred to as the sys­tem con­fig­u­ra­tion file.

There is a global con­fig­u­ra­tion file called .git­con­fig (note the lead­ing full stop). This is the one that gets used most and is the one we want to move. By de­fault, on a Win­dows ma­chine, it is lo­cated in:

C:\Users\<user­name>\.git­con­fig

Fi­nally, each repos­i­tory has its own local con­fig­u­ra­tion file called con­fig. This lives in the in­di­vid­ual repos­i­tory:

...\<repos­i­to­ry­name>\.git\con­fig"

But this is in­side the .git folder and we don’t go there (see § 2.2.1).

The order in which Git Bash ap­plies these con­fig­u­ra­tion files is:

  1. Mas­ter (sys­tem) con­fig­u­ra­tion (git­con­fig)

  2. Global con­fig­u­ra­tion (.git­con­fig)

  3. Local con­fig­u­ra­tion (con­fig)

Ef­fec­tively, the local con­fig­u­ra­tion has pri­or­ity be­cause it is ex­e­cuted last and any­thing in there will over­ride the oth­ers if there is a con­flict.

By de­fault the sys­tem con­fig­u­ra­tion and local con­fig­u­ra­tion are empty. Global con­fig­u­ra­tion is where the changes are made and this is the file whose lo­ca­tion I want to change.

To move the de­fault lo­ca­tion of the global con­fig­u­ra­tion file we need to edit an­other of the Git ini­tial­i­sa­tion files. This one is called pro­file and on a Win­dows ma­chine it lives here:

C:\Pro­gram Files\Git\etc\pro­file

The di­rec­tory in the mid­dle re­ally is called etc, I’m not ab­bre­vi­at­ing any­thing. Nav­i­gate to the file and edit it. It is a rea­son­ably large file (Code 3.1).

profile
  1. # To the extent possible under law, the author(s) have dedicated all
  2. # copyright and related and neighboring rights to this software to the
  3. # public domain worldwide. This software is distributed without any ...
  4. # You should have received a copy of the CC0 Public Domain Dedication along
  5. # with this software.
  6. # If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
  7.  
  8.  
  9. # System-wide profile file

  . . .

  1. clear
  2. echo
  3. echo
  4. echo "#############################################################"
  5. echo "# #"
  6. echo "# #"
  7. echo "# C A U T I O N #"
  8. echo "# #"
  9. echo "# This is first start of MSYS2. #"
  10. echo "# You MUST restart shell to apply necessary actions. #"
  11. echo "# #"
  12. echo "# #"
  13. echo "#############################################################"
  14. echo
  15. echo
  16. fi
  17. unset MAYBE_FIRST_START
  18.  
  19.  
  20. HOME="D:\2500 Git Projects"
  21.  
Code 3.1   Git profile configuration file additions

To change the de­fault (home) di­rec­tory we need to add a line to the very end of the file:

  1. HOME="D:\2500 Git Projects"

The syn­tax for this is:

HOME=path\to\home\folder

If any of the di­rec­tory names con­tain a space, put dou­ble quotes around the whole thing as I did with:

HOME="D:\2500 Git Pro­jects"

Now we just need to move the ex­ist­ing .git­con­fig (the one that was cre­ated when Git Bash was in­stalled) to the new lo­ca­tion.

In Win­dows Ex­plorer nav­i­gate to:

C:\Users\<user­name>\

Where <user­name>; is your user name on the ma­chine. This is what mine looks like:

Figure 3.21 - gitconfig file—original location

Figure 3.21   gitconfig file—original location

Se­lect .git­con­fig and then cut the file (ctrl+x), nav­i­gate to the new home di­rec­tory—in my case this is:

D:\2500 Git Pro­jects

And paste the cut file there (ctrl+v).

That’s it.

Setting the start directory

This is much eas­ier. On the desk­top there will be Git Bash icon:

Right click this icon and se­lect prop­er­ties, this opens the short­cut di­a­logue box (Fig­ure 3.22):

Figure 3.22 - Git Bash shortcut dialogue box

Figure 3.22   Git Bash shortcut dialogue box

Figure 3.23 - Modified Git Bash shortcut dialogue box

Figure 3.23   Modified Git Bash shortcut dialogue box

Two things to change here:

First in the start in box, enter the path to the new home di­rec­tory. In my case this is:

"D:\2500 Git Pro­jects"

Next, in the tar­get box re­move the --cd-to-home entry at the end. The final thing should look like Fig­ure 3.23:

That’s it, click ok and then click the icon to start Git Bash. This time it will start in your new home di­rec­tory. Mine looks like this:

Figure 3.24 - Git Bash with modified start folder

Figure 3.24   Git Bash with modified start folder

The bit in yel­low is the path to the cur­rent di­rec­tory (it’s in the UNIX style with D: re­placed with /d and obliques (/) in place of the re­verse obliques (\) that Win­dows uses for path names—but you get the idea).



End flourish image