DEV Community

Cover image for Best dotfiles manager is GIT
Michał Kalbarczyk
Michał Kalbarczyk

Posted on • Originally published at puddleofcode.com

1

Best dotfiles manager is GIT

Long story short. Tried lot of dotfiles managers including custom solutions. All of them have a big disadvantage. You have a copy of a file or symlink.
What do we need? Just git. Let's start!

First of all we need a shell alias to manage our files.

I'm using fish so creating alias looks like this.

$ alias hi "echo hello"
Enter fullscreen mode Exit fullscreen mode

But you can do same thing in bash as well:

$ alias hi="echo hello"
Enter fullscreen mode Exit fullscreen mode

Let's name our alias dot.

Just add such a line in your shell config file.

Depending on our needs we can:

Allow to backup files on whole disk:

alias dot "git --git-dir=$HOME/.dotfiles --work-tree=/"
Enter fullscreen mode Exit fullscreen mode

Or just in the home directory:

alias dot "git --git-dir=$HOME/.dotfiles --work-tree=$HOME"
Enter fullscreen mode Exit fullscreen mode

Great. We're just made an dot manager!

Let's init out repo

$ dot init
Enter fullscreen mode Exit fullscreen mode

One more thing! Need to set up one thing:

$ dot config --local status.showUntrackedFiles no
Enter fullscreen mode Exit fullscreen mode

And we're done. All git files are in $HOME/.dotfiles directory.

To add a file or directory we can simply:

$ dot add ~/.config
Enter fullscreen mode Exit fullscreen mode

and commit it with

$ dot commit
Enter fullscreen mode Exit fullscreen mode

The backup is a git repository. We can push it to github for example. Just add remote like on every other git repository.

Just like you saw. There is no copying, linking, just adding a files when something changed.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay