[Better Way] No Symlinks with usage as a bare repository - README needs updation.
kalkayan opened this issue · 1 comments
Manging dotfiles using symlink has been like a tradition and almost all the developers are doing it, if not having multiple copies of there dotfiles . But there exists a much better way - people at atlassian has written a very nice article about it using the git's --bare
feature and using it to store the dotfiles and I have to say this, it very elegant. The trick to managing these dotfiles is by creating a bare git repository.
The reason for this Issue is to make people aware about way and this repository is the best place for it, cause lets face it every developer trying to customize there os has or will peek into this repo atleast once.
Managing and tracking [dot]files with bare repo
I'm copy pasting it from https://github.com/kalkayan/dotfiles
Clone the repo as a bare repository and thats it! no problems related to symlinks.
# after forking replace the <username> with your github handle
git clone --bare https://github.com/<username>/dotfiles.git $HOME/.dotfiles
Notice the
--bare
flag, this the clones repository as a bare repository. Bare repository are special in a way that they omit working directory, therefore to use a bare repository, first we need to define the following.
--work-tree
- this can be your home directory, i.e.,$HOME
or~
)--git-dir
- where the repository is cloned -$HOME/.dotfiles
Therefore the command to use the repository will have a prefix
git --git-dir=$HOME/.dotfiles --work-tree=$HOME
,
Now next step is to checkout to the proper branch according to the os of the machine.
# checkout to main for macos and linux for ubuntu.
git --git-dir=$HOME/.dotfiles --work-tree=$HOME checkout main
Usage of dotfiles
This method of managing and sharing has various advantages some of them are shown below:
1. Keep the dofitles versioned, (basically all the cons of using git)
At this point, all your configuration files are being tracked, and you can easily use the dotfiles
command (see this line in .aliases) to manage the repository, some examples are:-
# to check the version history
dotfiles log
# to check the status of the tracked and untracked files
dotfiles status
# to add a file for tracking
dotfiles commit .vimrc -m ".vimrc added"
# push new files or changes to the github
dotfiles push origin main
⚠️ Thedotfiles status
will show all the untracked files to disable this behavior, do the following# to remove the untracked directories and files from the listing dotfiles config --local status.showUntrackedFiles no
2. Share on Multiple devices
Share the same configs of multiple devices with minimal changes using branch
, create a branch for your new machine, example:-
# Create configurations specific to your aws machines
dotfiles checkout -b aws
3. Create Profiles for dotfiles
Create configs based on your environment using branch
, create a branch and configure according to you work env.
# Manage multiple profiles - check out to the work profile
dotfiles checkout work