Instructions copied from the following article:
The Best Way to Store Your Dotfiles a Bare Git Repository Explained
Which is based on this article:
Dotfiles: Best Way to Store in a Bare Git Repository
- Set a Git repository’s work tree to
$HOME
git add
andcommit
your dotfiles to the Git repository. The dotfiles remain at their original paths.- Push your Git repository to a remote server such as GitHub. Now your dotfiles are backed up, and can be replicated.
Replicate your dotfiles by cloning down the repo, configuring it, and checking out the files. The files are checked out at their original paths relative to $HOME
.
git init --bare $HOME/.cfg
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bash_aliases
config config --local status.showUntrackedFiles no
config add <files>
+config commit -m "add things"
echo ".cfg" >> .gitignore
git clone --bare <remote-git-repo-url> $HOME/.cfg
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
config config --local status.showUntrackedFiles no
config checkout
-
git init --bare $HOME/.cfg
Create the folder.cfg
, a bare Git repository which will be used to track our dotfiles. -
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
Create an alias namedconfig
which allows you to send Git commands to the.cfg
repository from any location, even outside of the repository. It also configures the initially bare.cfg
repository to set$HOME
as the work tree, and store the Git state at.cfg
. -
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bash_aliases
Make theconfig
alias permanently available. -
config config --local status.showUntrackedFiles no
Only show config files manually added, not every file under$HOME
. -
add
,commit
andpush
to the remote
Use theconfig
alias toadd
andcommit
files from any directory.
config remote add origin <remote-url>
config push -u origin master
-
echo ".cfg" >> .gitignore
There could be weird behaviour if.cfg
tries to track itself. Avoid recursive issues by adding.cfg
to your global Git ignore. -
git clone --bare <remote-git-repo-url> $HOME/.cfg
Clone the dotfile repo to your.cfg
directory. -
alias config='/usr/bin/git --git-dir=$HOME/.cfg --work-tree=$HOME'
Set up an alias to send Git commands to.cfg
, and also set$HOME
as the work tree, while storing the Git state at.cfg
-
config config --local status.showUntrackedFiles no
Set a local configuration in.cfg
to ignore untracked files. -
config checkout
Checkout the actual content from your dotfile repository to$HOME
.
config checkout
might fail with a message like:error: The following untracked working tree files would be overritten by checkout: .bashrc .gitignore Please move or remove them before you can switch branches. Aborting
Git doesn’t want to overwrite your local files. Back up the files if they’re useful, delete them if they aren’t.
In no particular order:
- alacritty
- i3
- i3status
- nvim
- picom
- feh