.bak | ||
.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 involves storing a Git bare repository in a "side" folder, such as $HOME/.dot
or $HOME/.myconfig
, using a specially crafted alias.
This ensures that commands are run against the repository itself and not the local .git
folder, which could interfere with other Git repositories.
Starting from scratch
git init --bare $HOME/.dot
alias dot='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME'
dot config --local status.showUntrackedFiles no
echo "alias dot='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME'" >> $HOME/.bashrc
git init --bare $nu.home-path/.dot
alias dot = git --git-dir=($nu.home-path | path join .dot) --work-tree=($nu.home-path)
dot config --local status.showUntrackedFiles no
"alias dot = git --git-dir=($nu.home-path | path join .dot) --work-tree=($nu.home-path)" | save --append ($nu.home-path | path join .config/nushell/config.nu)
- The first line creates a folder
~/.dot
which is a Git bare repository that will track our files. - Then we create an alias
dot
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 dot
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 dot='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME'
alias dot = git --git-dir=($nu.home-path | path join .dot) --work-tree=($nu.home-path)
- And that your source repository ignores the folder where you'll clone it, so that you don't create weird recursion problems:
echo ".dot" >> .gitignore
".dot" | save --append .gitignore
- Now clone your dotfiles into a bare repository in a "dot" folder of your
$HOME
:
git clone --bare <git-repo-url> $HOME/.dot
git clone --bare <git-repo-url> ($nu.home-path | path join .dot)
- Define the alias in the current shell scope:
alias config='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME'
alias dot = git --git-dir=($nu.home-path | path join .dot) --work-tree=($nu.home-path)
- Check out 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 $HOME
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 .dot-backup && \
dot checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | \
xargs -I{} mv {} .dot-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
dot
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