Fattie
Fattie

Reputation: 12354

git, dot-git folder and other files found in home folder?

On a Mac used for Unity development, it's all svn, but there's only one folder used with a server git repo, /User/myname/clients/blah/project

Now I happened to be using Android Studio and (like most IDEs now) it tries to do source control for you. I got a pop up alerting me there is an "unregistered source", in fact at my home folder.

So at /User/myname I found these files ..

$ ls -la
.git
.gitconfig
.gitignore_global

Well now, in the folder under source control /User/myname/clients/blah/project there is indeed

$ ls -la
.git
.svn

and it all works great.

The text file ".gitconfig" appears to have my password, etc, for logging in to the server in question for the repo of /User/myname/clients/blah/project.

What I don't understand:

Can I just get rid of the .git directory in my home directory?

(Perhaps, I just accidentally started a git there or something?)

Or indeed, does Git "need" a .git folder in your home directory, as well as a .git directory in the folder under control?

Or, do I not understand "unregistered source" - ?

Specifically, would it be safe and harmless to delete that .git folder in the home directory ?

Further, Git seems to have chosen to use my "home" directory for preferences/etc rather than the folder /User/myname/clients/blah/project where I was actually using it. Is that my stuff up or is it just what Git does?


Based on the incredible answer below, I went to the home directory, and

$ git log

and got this:

fatal: your current branch 'master' does not have any commits yet

When I "git log" in the /User/myname/clients/blah/project directory, it indeed shows a long list of commits which I did for that project over the years.

Does this suggest I can just plain delete the .git folder in the home directory?

Upvotes: 1

Views: 1590

Answers (1)

msrd0
msrd0

Reputation: 8390

The .git directory in your home folder

It is not required.

I'm using git heavily and git didn't create that directory on my machine. Before deleting it, I would recommend you to look whats inside the git repository, by executing git log. If it's empty, it is safe to delete it. If it's not empty, you can create a new clone by doing git clone $HOME/.git strangerepo. Then, look at the folder strangerepo to see the content of the git repo.

EDIT: Keep in mind that the working directory is relevant when executing the git command. If git is not currently inside a git repository, it will go to the parent directory and search for a .git folder there. When it reaches /, it will output an error that no repository was found. So executing git log in $HOME will have a different result than running it in $HOME/path/to/your/repo.

The .gitconfig file

Don't delete it. Git uses it.

To use git, you need to tell git your name and your email. You do so with commands that look like that:

git config --global what.ever value

These config is saved in $HOME/.gitconfig. If you call git config without the --global flag (inside a git repo directory), git will only save the config for the specific repository. But of course this file does not need to contain your password - a file looking like this is just fine:

[user]
    email = [email protected]
    name= XYZ

Upvotes: 1

Related Questions