Versioning my home with git on mac
In Windows it is much simpler. You just start repo in your use directory.
In Linux/Mac it is one problem. your home directory (~/
) is the root for everything. When I create a folder:
$ cd ~
$ git init
$ mkdir tests
$ cd tests
$ git status
Then folder /tests
thinks it is under version control.
Create a bare repo in different folder
But when we will create bare repository then we can remove that problem.
Init
How to init:
$ git init --bare ~/.githome
$ touch README.md
$ git --work-tree="${HOME}" --git-dir="${HOME}/.githome" add README.md
$ git --work-tree="${HOME}" --git-dir="${HOME}/.githome" commit -m init
Alias
For later usages I suggest an alias (placed in .zshrc
):
alias gh='git --work-tree="${HOME}" --git-dir="${HOME}/.githome"'
alias githome='git --work-tree="${HOME}" --git-dir="${HOME}/.githome"'
(both are the same, I prefer shorter version, but maybe you prefer to be more explicit)
I don’t have to type the full command every time. I can just use:
$ gh add .zshrc
$ gh commit -m 'version .zshrc'
Where to backup the code
Above is the way how to store it in local bare repository. Of course it will be much better when you push your changes to some private repo. I suggest creating private repository on Github or Gitlab (it is free).
Not show the untracked files
$ gh config --local status.showUntrackedFiles no
The --local
switch tells to apply this settings only to this repo and not for the whole system.
Thanks Jakub Kozioł for showing me that 4 yours ago.
More robust explanation: The Bare Repo Approach to Storing Home Directory Config Files (Dotfiles) in Git using Bash, Zsh, or Powershell