Dotfiles, the Prequel: Easy and Fast
Jonathan Bowman Created: February 07, 2021 Updated: July 10, 2023 [Dev] #dotfiles #commandline #gitIn my ongoing quest to explore a variety of ways of managing config files, I believe I have found a way that is attractively simple.
In the following steps, the $REPO_URL should be replaced with (or assigned a value of) the remote URL for the git repo you are using to store your dotfiles. It may look like [email protected]:USERNAME/dotfiles.git or https://github.com/USERNAME/dotfiles.git, for instance, with your username in place of USERNAME and your repository name in place of dotfiles.
πStep one: git clone
Rationale:
- using git cloneensures that the default branch is checked out (specify-b branchnamefor a different branch than the default)
- status.showUntrackedFilesis set to βnoβ so that future- git statusrequests only show files that were intentionally tracked with- git addand- git commit
- -nmeans no checkout. We arenβt ready for it yet.
- --separate-git-dir .gittakes some explanation. It is impossible to- git cloneinto 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 but easily-removable side effect is an extra directory tmpdirthat has a single.gitfile of no consequence. The entire directory can safely be removed.
πStep two for non-empty repo: git checkout
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:
π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:
Repeat as necessary with additional files and directories. Then push:
π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 send me feedback!