Gangmax Blog

Put dotfiles into Git

You may need your dotfiles for different computers or even one computer as time going. To achieve it you can put them into Git.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# List all regular dotfiles under "~" (level one only) without "." or "..".
find ~ -maxdepth 1 -type f -regextype egrep -regex "^/home/`echo $USER`/\.[^\.]+"

# Make a target directory to contain the dotfiles.
mkdir dotfiles

# Initial the ".gitignore" file with all the dotfiles(only once),
# which means all the dotfiles are ignored by default. The "cut"
# command removes the "/home/$HOME/" prefix of each item in the
# result of the "find" command execution.
find ~ -maxdepth 1 -type f -regextype egrep -regex "^/home/`echo $USER`/\.[^\.]+" | cut -c`expr length + "echo $HOME" - 3`- > dotfiles/.gitignore

# Copy all of dotfiles into the target directory.
find ~ -maxdepth 1 -type f -regextype egrep -regex "^/home/`echo $USER`/\.[^\.]+" | xargs -I{} cp {} dotfiles/

# Now you can edit the ".gitignore" file to enable the files which
# you want to put into Git by removing the corresponding line(s).
# Then use the following Git command to push the files into Git.
cd dotfiles/
git init .
git add .
git commit -m 'The initial commit of the dotfiles.'
# Before executing the following command, you should create
# the new Git repo in Github.
git remote add https://github.com/youraccount/dotfiles.git
git push

From 1, 2, 3, 4, 5, 6 and 7.

Comments