Dotfiles
Table of Contents
- 1. Description
- 2. Initialize the bare repo
- 3. Set an alias
- 4. Add files for Git to track
- 5. Commit the changes
- 6. List tracked files
- 7. Turn off output about untracked files when running
cfg status - 8. Add
fooas remote - 9. Track the remote
mainbranch - 10. Pushing the changes from now on
- 11. Restoring the dotfiles
- 12. References
1. Description
Notes about how to backup and restore configuration files (dotfiles) using a Git bare repository
2. Initialize the bare repo
git init --bare ~/.dotfiles
3. Set an alias
3.1. Bash
Add to ~/.bashrc
alias cfg='git --git-dir="$HOME/.dotfiles" --work-tree="$HOME"'
3.2. Fish
Add this fish shell function to ~/.config/fish/functions/cfg.fish
function cfg command git --git-dir="$HOME/.dotfiles" --work-tree="$HOME" $argv end
4. Add files for Git to track
cfg add .bashrc
5. Commit the changes
cfg commit
6. List tracked files
cfg ls-files
7. Turn off output about untracked files when running cfg status
cfg config --local status.showUntrackedFiles no
8. Add foo as remote
cfg remote add foo git@foo:username/dotfiles.git
9. Track the remote main branch
cfg push --all -u foo
10. Pushing the changes from now on
cfg push foo
11. Restoring the dotfiles
Restoring the dotfiles when the alias might not be set, e.g. on a new install
11.1. Clone the bare repository
git clone --bare <url>/dotfiles.git ~/.dotfiles
11.2. Restoring
git --git-dir="$HOME/.dotfiles" --work-tree="$HOME" restore --staged --worktree --source HEAD "$HOME"