Skip to content

Instantly share code, notes, and snippets.

@lonetwin
Last active October 2, 2023 13:38
Show Gist options
  • Star 54 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save lonetwin/9636897 to your computer and use it in GitHub Desktop.
Save lonetwin/9636897 to your computer and use it in GitHub Desktop.
A simple way to manage dotfiles with git without silly symlinks and special tools. Just use negative matches in your .gitignore !
I like to manage dotfiles without having to mess with silly symlinks or having
to install/configure specific dotfile managament tools. So here's what I did:
$ cd ~
$ git init .
$ echo '*' > .gitignore # ignore all files by default
$ echo '!.bashrc' >> .gitignore # ...and then tell git what files not to *not* ignore
$ # ...add other files you may want to track to *not* ignore
$ git add .bashrc # now actually add the files to git
$ git add .gitignore # add the .gitignore to git
$ git submodule add -f git@github.com:lonetwin/lonetvim.git .vim
$ # ...and any other remote repos you may want to track
$ git commit # ..and you're done !!
# import into github if you prefer
# Create different 'profiles' as branches (eg: work_profile, home_profile, dev_box ...)
Now, on the next system you want to recreate the dot files:
$ git init .
$ git remote add origin <url to your repo>
$ git fetch
$ # rm .bashrc ... # any files that are present by OS default
$ git checkout <branch name> # ...and you're done !!
@lonetwin
Copy link
Author

One note about profiles, I currently put all the common stuff for my dotfiles into my master branch (eg: a bash alias or function that is useful at both work and home) and the profile-specific stuff on the profile branch. Everytime I update master, I merge it into the profile branches but never the other way round. I should learn more about git worktree though.

@frkd-dev
Copy link

Here what I've found on HN some time ago:

git init --bare $HOME/.myconf
alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
config config status.showUntrackedFiles no

where my ~/.myconf directory is a git bare repository. Then any file within the home folder can be versioned with normal commands like:

config status
config add .vimrc
config commit -m "Add vimrc"
config add .config/redshift.conf
config commit -m "Add redshift config"
config push

Copy link

ghost commented Jan 29, 2022

been doing this for a good while now,
thanks for making this guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment