Last active
May 20, 2024 23:21
-
-
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 !
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [email protected]: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 !! |
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
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
One note about
profiles
, I currently put all the common stuff for my dotfiles into mymaster
branch (eg: a bash alias or function that is useful at both work and home) and theprofile-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 aboutgit worktree
though.