Dotfiles
Creating a Dotfiles system
Creating a Dotfiles system
Setup your shell
export DOTFILES_DIR="$HOME/.dotfiles" # or elsewhere
alias dotfiles='git --git-dir="$DOTFILES_DIR" --work-tree="$HOME"'
or for fish
:
set -x DOTFILES_DIR "$HOME/.dotfiles"
function dotfiles
git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" $argv
end
Create bare repository
Note the
git
instead ofdotfiles
git init --bare "$DOTFILES_DIR"
and push it afterwards using dotfiles
:
dotfiles push
git should assist you setting the remote.
Note on public and private dotfile repository
Only make your dotfiles public if you are 100% sure that you have pushed or will push only content that you are absolutely comfortable with being seen by anyone, known or unknown.
Configure to ignore unknown files
dotfiles config --local status.showUntrackedFiles no
Restoring Dotfiles
Restoring Dotfiles
Setup an alias (temporarily inside the shell, you should have them already in a file that is being restored)
export DOTFILES_DIR="$HOME/.dotfiles" # or elsewhere
alias dotfiles='git --git-dir="$DOTFILES_DIR" --work-tree="$HOME"'
Clone the bare repository
The cloning depends on whether your Dotfiles repository is public or private.
a) If your Dotfiles are public, you can simply call
git clone --bare "<git-repo-url>" "$DOTFILES_DIR"
b) If they are private, you can create a token that can read the repository.
On GitHub, go to
Settings > Developer Settings > Personal Access Token > fine-grained tokens
.
Create a new token that you limit to the shortest possible time and only allow access to this one repository. Lastly, allowread-only
access to theContent
of the repository.
git clone --bare <token@git-repo-url> "$DOTFILES_DIR"
e.g.
git clone --bare https://tokentokentoken@github.com/bjoernahrens/dotfiles.git "$DOTFILES_DIR"
Restore the files
dotfiles checkout
The checkout
might fail because you or your system already created some of your dotfiles:
error: The following untracked working tree files would be overwritten by checkout:
.zshrc
.gitconfig
Please move or remove them before you can switch branches.
Aborting
The easiest option is to simply delete the files.
If they are part of your existing dotfiles (and you have not added any life-changing features), that should be fine.
Alternative: Backup your existing files
mkdir -p .config-backup && \
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | \
xargs -I{} mv {} .config-backup/{}
Rerun the checkout
command:
dotfiles checkout
Configure to ignore unknown files
dotfiles --local status.showUntrackedFiles no