.config | ||
.librewolf | ||
.local | ||
.bash_aliases | ||
.gitconfig | ||
.gitconfig.catppuccin | ||
.gitconfig.personal | ||
.gitignore | ||
.gitmessage | ||
README.md |
💾 Dotfiles: Bare git repository
https://www.atlassian.com/git/tutorials/dotfiles
The technique consists in storing a Git bare repository in a "side" folder (like $nu.home-path/.cfg
or $nu.home-path/.myconfig
) using a specially crafted alias so that commands are run against that repository and not the usual .git
local folder, which would interfere with any other Git repositories around.
Starting from scratch
git init --bare $nu.home-path/.cfg
alias dot = git --git-dir=($nu.home-path | path join .cfg) --work-tree=($nu.home-path)
dot config --local status.showUntrackedFiles no
- The first line creates a folder
~/.cfg
which is a Git bare repository that will track our files. - Then we create an alias
config
which we will use instead of the regulargit
when we want to interact with our configuration repository. - We set a flag - local to the repository - to hide files we are not explicitly tracking yet. This is so that when you type
config status
and other commands later, files you are not interested in tracking will not show up asuntracked
.
Once you've run the setup, any file in the $HOME
folder can be versioned using normal commands, replacing git
with your newly created config
alias, such as:
dot status
dot add .vimrc
dot commit -m "Add vimrc"
dot add .bashrc
dot commit -m "Add bashrc"
dot push
Installing your dotfiles onto a new system (or migrate to this setup)
If you already store your configuration/dotfiles in a Git repository, on a new system you can migrate to this setup with the following steps:
- Prior to the installation make sure you have committed the alias to your
.bashrc
or.zsh
:
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
- And that your source repository ignores the folder where you'll clone it, so that you don't create weird recursion problems:
echo ".cfg" >> .gitignore
- Now clone your dotfiles into a bare repository in a "dot" folder of your
$nu.home-path
:
git clone --bare <git-repo-url> $nu.home-path/.cfg
- Define the alias in the current shell scope:
alias dot = git --git-dir=($nu.home-path | path join .cfg) --work-tree=($nu.home-path)
- Checkout the actual content from the bare repository to your
$HOME
:
dot checkout
- The step above might fail with a message like:
error: The following untracked working tree files would be overwritten by checkout:
.bashrc
.gitignore
Please move or remove them before you can switch branches.
Aborting
This is because your $nu.home-path
folder might already have some stock configuration files which would be overwritten by Git. The solution is simple: back up the files if you care about them, remove them if you don't care. I provide you with a possible rough shortcut to move all the offending files automatically to a backup folder:
mkdir -p .cfg-backup && \
dot checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | \
xargs -I{} mv {} .cfg-backup/{}
- Re-run the check out if you had problems:
dot checkout
- Set the flag
showUntrackedFiles
tono
on this specific (local) repository:
dot config --local status.showUntrackedFiles no
- You're done, from now on you can now type
config
commands to add and update your dotfiles:
dot status
dot add .vimrc
dot commit -m "Add vimrc"
dot add .bashrc
dot commit -m "Add bashrc"
dot push