DEV Community

Cover image for Dotfiles the easy way
Jonathan Bowman
Jonathan Bowman

Posted on • Edited on • Originally published at bowmanjd.com

2 1

Dotfiles the easy way

In my ongoing quest to explore a variety of ways of managing config files, I believe I have found a way that is attractively simple.

Step one: git clone

cd ~
git clone -c status.showUntrackedFiles=no -n --separate-git-dir .git $REPO_URL tmpdir
rm -r tmpdir
Enter fullscreen mode Exit fullscreen mode

Rationale:

  • status.showUntrackedFiles is set to "no" so that future git status requests only show files that were intentionally tracked with git add and git commit
  • -n means no checkout. We aren't ready for it yet.
  • --separate-git-dir .git takes some explanation. It is impossible to git clone into a non-empty directory without some extra steps. This trick does it in one step (two if you count the deletion of the throwaway directory). Tell Git to use a separate Git directory but then, sneaky miscreants that we are, we name the directory the default: .git
  • The undesirable side effect is an extra directory tmpdir that has a single .git file of no consequence. The entire directory can safely be removed.

Step two for non-empty repo: git checkout

git checkout
Enter fullscreen mode Exit fullscreen mode

Deal with any file conflicts. For instance, you might backup and remove an existing .bashrc. Then run git checkout again. If you are sure that overwriting is OK, you can pass the force flag:

git checkout -f
Enter fullscreen mode Exit fullscreen mode

Step two if new (empty) repo: add files and push

If this is a brand new setup, your repo is likely empty. Add some files:

git add .bashrc
git commit -m "initial commit of Bash config"
Enter fullscreen mode Exit fullscreen mode

Repeat as necessary with additional files and directories. Then push:

git push
Enter fullscreen mode Exit fullscreen mode

Step three: maintain

Keep your files up to date with git add, git commit, git push. Pull remote changes with git pull. In other words, manage your home directory as you would any other Git repo. Please avoid git add . as that will track every file in your home directory, an undesirable endeavor.

If this spawns other creative ideas or optimizations, feel free to post in the comments!

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

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

Okay