Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force git to add dotfiles to repository

Tags:

git

file

hidden

Git seems to always ignore these.

When I type git add ., dotfiles in GIT_DIR are added, but not from subdirectories. On the other hand, git add subdir/.dotfile won't work.

I tried git add -f and putting !.* in GIT_DIR/.git/info/exclude.

like image 316
Sergey Kovalev Avatar asked Feb 28 '10 20:02

Sergey Kovalev


People also ask

Where do you put dotfiles?

You need to organize your dotfiles in some directory. You could do this practically anywhere, like a USB drive or something. Since version control is great, a hosted git repository like GitHub is a great option to store your dotfiles.

How do I update dotfiles?

Whenever you want to add a new update to your dotfiles, all you need to do is simply open the dotfile in your home directory like normal. Edit it as you would any other day and then save the file.

How do I add files to an existing repository?

To add and commit files to a Git repository Create your new files or edit existing files in your local project directory. Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.


Video Answer


1 Answers

git add . and git add dir/.dot work fine for me with the unadorned 1.6.6.1 and 1.7.0 versions of Git that I have handy right now.

% git --version git version 1.6.6.1 % git ls-files -o .baz/baz .foo bar/.bar quuux/quuux quux % git add . % git ls-files -o % git ls-files  .baz/baz .foo bar/.bar quuux/quuux quux 

What version of Git are you using? Are your subdirs actually submodules (which are managed independently)?

“dot files” are not excluded by default, but maybe some bit of configuration on your system, repository, or working tree has them set that way. If they show up in git ls-files --exclude-standard -oi then they are being ignored and "!.*" is the right way to ‘unignore’ them. But to be effective, that pattern has to be in the right place. Ignores are processed in this order:

  • .gitignore of the immediately containing directory, then
  • .gitignore of the parent directory (each parent, up to the repository root), then
  • $GIT_DIR/info/exclude, then
  • the file reported by git config core.excludesfile (which could be set by
    • $GIT_DIR/config,
    • $HOME/.gitconfig, or
    • the system config file (try GIT_EDITOR=echo git config --system --edit to get its pathname)).

When a pathname matches a pattern in one file, subsequent files are not consulted. The last match in each file “wins”. A pattern in $GIT_DIR/info/exclude can never override a pattern in a .gitignore file. So, if the files are being ignored (per git ls-files --exclude-standard -oi) and if "!.*" in $GIT_DIR/info/exclude is ineffective, then check all the applicable .gitignore files for the culprit.

like image 170
Chris Johnsen Avatar answered Sep 20 '22 13:09

Chris Johnsen