Skip to content

Instantly share code, notes, and snippets.

@w0ltage
Last active August 18, 2023 07:33
Show Gist options
  • Save w0ltage/b96349b0a1908e3e246ec8d5d6ce8caf to your computer and use it in GitHub Desktop.
Save w0ltage/b96349b0a1908e3e246ec8d5d6ce8caf to your computer and use it in GitHub Desktop.
Init git bare repository
#!/bin/bash
# Inspired by https://www.atlassian.com/git/tutorials/dotfiles
[ $# -eq 0 ] && { echo "Usage: $0 <shell-config-file>"; exit 1; }
SHELL_CONFIG=$1
BARE_REPO_PATH=$HOME/.dotfiles
git init --bare $BARE_REPO_PATH
echo "alias config='/usr/bin/git --git-dir=$BARE_REPO_PATH --work-tree=$HOME'" >> $HOME/$SHELL_CONFIG
source $SHELL_CONFIG
printf "Bare git repository created at $BARE_REPO_PATH\nInteract with config repo by using 'config' as command, not 'git'\n"
printf "\nExample:\nconfig add .vimrc .zshrc .config/tmux/tmux.conf\nconfig commit -m 'Add .vimrc, .zshrc and tmux.conf'\nconfig remote add origin <remote-repo-url>\nconfig push -u origin <branch>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment