Skip to content

Instantly share code, notes, and snippets.

@dberstein
Last active February 7, 2021 13:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dberstein/f0c673b9d7275d162bb65fbb60091f54 to your computer and use it in GitHub Desktop.
Save dberstein/f0c673b9d7275d162bb65fbb60091f54 to your computer and use it in GitHub Desktop.
simple git alias for dotfiles management
# git-dotfiles: simple git alias for dotfiles management
# 1. configure dotfiles checkout location ...
git config --global --replace-all dotfiles.dir "$HOME/.dotfiles"
# 2. init dotfiles ...
git init --bare "$(git config --global dotfiles.dir)"
# 3. create git dotfiles alias ...
git config --global --replace-all alias.dotfiles '!git --git-dir="$(git config --global dotfiles.dir)" --work-tree="$HOME"'
# 4. (OPTIONAL)
echo \* >> $HOME/.gitignore
# Usage: git dotfiles ...
# $ git dotfiles add -f $HOME/.bashrc $HOME/.bash_profile ...
# $ git dotfiles commit -m '...' ...
# $ git dotfiles remote add ...
# $ git dotfiles push ...
# Alternative dotfiles alias:
cat <<EOS | tee "$HOME/.bashrc"
alias dotfiles="/usr/bin/git --git-dir='$(git config --global dotfiles.dir)' --work-tree='$HOME'"
EOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment