Git-aux is a simple script to help with managing a collection of often-used, often-replicated files such as dotfiles in a home directory.
Using git-aux, you can create a repository, add files to it from a chosen folder (e.g. your home directory), push the changes and keep the necessary files in sync between different machines.
Using git's already-powerful branching, merging, and rebasing, you can keep modified versions of a home folder in sync.
To use git-aux, just add it to your path and it will be usable either as
When in a git repository, initialise git aux to map the repository root to the specified directory.
If the given file is not within the git aux base dir, an error is raise.
Otherwise, add the chosen file to the repository.
Check all files that have been
git aux added for changes outside of the repository and interactively merge them in.
Apply any changes to files in the repository to the corresponding files in the base dir.
To manage files in your home dir with git aux, do this:
git init .
git aux init /home/bungle
git aux add /home/bungle/.vimrc /home/bungle/todo_list.txt
git commit -m "Added vimrc and my todo list
git remote add origin firstname.lastname@example.org:aux_home.git
git push -u origin master
Later, on another machine:
git clone email@example.com:aux_home.git
git aux init /home/zippy
git aux apply
echo Buy some milk >> /home/zippy/todo_list.txt
git aux sync
Often, you will find that you want to keep most of a file in sync but have changes on some machines. I find my
.bashrc is frequently an example of this.
To get around the issue, I use a
master branch to represent a base set of what I want in my home dir and then a separate branch per machine to hold machine-specific modifications.
For example, I might want the following in my
.bashrc on all machines:
alias ls="ls --color=auto" export PATH=$PATH:~/bin
But on my work machine, I may want to add another entry to
alias ls="ls --color=auto" export PATH=$PATH:~/bin:/opt/android/bin
The solution is to add the basic
.bashrc above to the
master branch then switch to the
work branch and make the changes. If I later want to add something new to all of my machines, I add it to the
When I come to apply changes on my work machine, I checkout the
work branch and rebase it with
master. That way I get the new features but also keep my work-specific modifications.