Skip to content

Instantly share code, notes, and snippets.

@dvogeldev
Created April 1, 2020 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvogeldev/2091ffea60d5f1062a090b0204971e99 to your computer and use it in GitHub Desktop.
Save dvogeldev/2091ffea60d5f1062a090b0204971e99 to your computer and use it in GitHub Desktop.
Instructions for the dotfile repository on https://github.com/weibeld/dotfiles

Dotfiles

Instructions for the dotfile repository on https://github.com/weibeld/dotfiles.

Introduction

The dotfiles in this repository are installed using a bare Git repository. This method does not use symlinks (like most other dotfile repositories).

After the installation, all the dotfiles will be physically present in your home folder, yet, you will still have them under full version control.

Installation

curl -Lks http://bit.ly/get-my-dotfiles | bash

The URL http://bit.ly/get-my-dotfiles is simply a shortened link to the dotfiles-install.sh file in this Gist, and the above command downloads this file and executes it in a sub-shell.

In particular, the dotfiles-install.sh file does the following:

  • Clone the dotfile repository to a bare Git repository into ~/.dotfiles
  • Move your existing dotfiles to ~/.dotfiles.backup
  • Check out all the dotfiles (and dot-directories) to your home directory

If you don't need your old dotfiles anymore, you can safely delete the created ~/.dotfiles.backup directory.

And Now?

Now all the dotfiles from the repository are installed in your home directory. However, as mentioned, you still have them under full version control via the bare Git repository in ~/.dotfiles.

To interact with the bare Git repository, you need the following alias:

alias dotfiles='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'

Note: the .bashrc file in the dotfile repository already contains this alias definition, so you're fine to go.

With the dotfiles alias, you can now manage the dotfiles via the bare Git repository, just as you would with the git command:

Edited your dotfiles? No problem, commit and push the changes:

dotfiles add ~/.vimrc
dotfiles commit -m "Edit .vimrc"
dotfiles push

Pushed changes to the remote repository from another machine? Easy, just pull down the new version:

dotfiles pull

Want to know what's going on? Sure:

dotfiles status

Submodules

The dotfile repository supports submodules (Git repositories within another Git repository).

The case for submodules occurs typically with Vim plugins, if you install them with pathogen.vim by cloning the respective Git repository into a directory under ~/.vim/bundle.

Here are some common tasks when using submodules:

  • Add a Vim plugin as a submodule to the repository:

    dotfiles submodule add https://github.com/tpope/vim-surround .vim/bundle/vim-surround
    dotfiles commit
    dotfiles push
    # Download files of submodule on local machine
    dotfiles submodule init
  • Pull changes that inlude a newly added submodule on another machine:

    dotfiles pull
    dotfiles submodule init
    dotfiles submodule update
  • List all submodules in the repository (including the commit that is used for each submodule):

    dotfiles submodule status
  • Update the submodules in the repository to the newest commits:

    dotfiles submodule update --remote
    dotfiles add <changed_files>
    dotfiles commit

References

The used installation method using a bare Git repository is described here:

# Installation script (Bash) for https://github.com/weibeld/dotfiles
set -e
#------------------------------------------------------------------------------#
# Download
#------------------------------------------------------------------------------#
echo "> Downloading dotfiles..."
dir=.dotfiles
git clone --quiet --bare https://github.com/weibeld/dotfiles "$HOME/$dir"
cmd() { git --git-dir="$HOME/$dir" --work-tree="$HOME" "$@"; }
#------------------------------------------------------------------------------#
# Backup already existing dotfiles
#------------------------------------------------------------------------------#
files=($(cmd ls-tree -r HEAD | awk '{print $NF}'))
bkp=.dotfiles.backup
for f in "${files[@]}"; do
# File at root ==> back up file
if [[ $(basename "$f") = "$f" ]]; then
[[ -f "$HOME/$f" ]] && mkdir -p "$HOME/$bkp" && mv "$HOME/$f" "$HOME/$bkp" && echo "> Backing up: $f ==> $bkp/$f"
# File in nested directory ==> back up outermost directory
else
d=${f%%/*}
if [[ -d "$HOME/$d" ]]; then
[[ -d "$HOME/$bkp/$d" ]] && rm -rf "$HOME/$bkp/$d"
mkdir -p "$HOME/$bkp" && mv "$HOME/$d" "$HOME/$bkp" && echo "> Backing up: $d/ ==> $bkp/$d/"
fi
fi
done
#------------------------------------------------------------------------------#
# Install
#------------------------------------------------------------------------------#
cmd checkout
cmd submodule --quiet init
cmd submodule --quiet update
cmd config status.showUntrackedFiles no
echo "> Success! The following dotfiles have been installed to $HOME:"
printf ' %s\n' "${files[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment