Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Am I abusing git by making my home directory a repo and then having other repos within it? [closed]

Tags:

git

For years, I've set up my home directory as a git repo:

~ $ ls -a
.git/  .vim/  code/  .bash_history  .bashrc  .gitconfig  .gitignore  .vimrc

I'm careful not to commit files that contain sensitive information (e.g. my private ssh key). In fact, I ignore everything except a few files:

~ $ cat .gitignore
# ignore everything
*

# except these
!.bashrc
!.gitignore
!.vimrc

Normally, I have several projects in code/ with their own git repos:

~ $ ls -a code/
ctest/  cpptest/  dwm/

~ $ ls -a code/ctest/
.git/  pointers  pointers.c  strings  strings.c

It never occurred to me that this was strange until a coworker raised concerns about it. Am I somehow abusing git by setting up my home directory this way? Can it lead to problems with programs attempting to use my dot files?

like image 609
Big McLargeHuge Avatar asked Dec 11 '15 16:12

Big McLargeHuge


People also ask

Can I have multiple git repositories in one folder?

Yes, it is possible to have two git repositories in one directory.

Can I have a repo inside another repo?

Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.

Can you clone a repo more than once?

Yes, it is possible. Just do git clone in two different directories with two different repositories.


1 Answers

It's definitely not crazy to put your dotfiles in git. I do it so that I can easily sync my configuration among multiple machines and I'm not alone.

That said, it is poor form to have a git repository in your home directory and then have other repos beneath it.

Some people solve this by checking out their dotfiles repo into a sub directory of $HOME and then symlinking those files into home. (There are some scripts to help manage this at https://dotfiles.github.io.

Personally, I don't like symlinking and instead create my dotfiles repo in a directory that is not .git (for example: .dotfiles.git). You can simply rename the .git folder to .dotfiles.git. Then you can:

git checkout --git-dir=.dotfiles.git checkout .profile
like image 170
Edward Thomson Avatar answered Sep 17 '22 16:09

Edward Thomson