我将我的dotfiles存储在github中,因为没有自动化,所以很费劲。我必须自己更新。
有没有办法可以自动安装/更新/同步dotfiles?我的意思是在一个新的服务器,我下载dotfiles并执行install
脚本将dotfiles复制到本地。过了一段时间,我可以执行一个updateToRemote
脚本来将本地更改推送到远程仓库,在另一台服务器上,我可以执行一个updateToLocal
脚本来将远程更改拉到本地。
这样的事情。
关于dotfiles的主要信息来源是dotfiles.github.io
。
它引用了基于符号链接方法的Using Git and Github to Manage Your Dotfiles等博客文章。
对于初学者,我们将所有的dotfiles放入一个名为dotfiles的文件夹中,如下所示:
/home/smalleycreative/dotfiles/vimrc
。 然后,我们将简单地从我们的主目录中对它们进行符号链接。
Jaime提到Atlassian教程“The best way to store your dotfiles: A bare Git repository”
该技术包括使用特制的别名将Git裸存储库存储在“side”文件夹(如
$HOME/.cfg
或$HOME/.myconfig
)中,以便针对该存储库运行命令,而不是通常的.git/
本地文件夹,这会干扰任何其他Git存储库周围。 (然后dotfiles文件夹作为git repo进行管理)
上面的答案非常好,而且正是我在“真实操作系统”上的表现。
我在使用cygwin / msys的着名商业操作系统上遇到了这个问题,因此使用符号链接有时可能会出现一些我最喜欢的软件的“本机”端口。
为了解决这个问题,我尝试将文件夹$ HOME直接作为git存储库。在一些失败后,我发现密钥全部在.gitignore文件中。
因此,我已经使用了一段时间的设置是通过将$ HOME设置为存储库,制作.gitignore文件以及单独添加所需的“dotfiles”文件来创建的。我还在备份驱动器(z:在本例中为z)中添加了一个存储库作为上游,以获得自动备份。如果您的文件夹已备份,则添加上游是不必要的复杂问题。因此,假设“/z/Backups/Dotfiles.git”是一个预先存在的“裸”存储库,在msys shell中,设置的步骤是:
$ cd $HOME
$ git init
Initialised empty Git repository in $HOME
$ git add .bashrc .emacs .gitconfig # for example
$ git commit -m "Initial import of dotfiles"
[master (root-commit) xxxxxxxx] Initial import for dotfiles
3 files changed, xxx instertions(+)
create mode 100644 .bashrc
create mode 100644 .emacs
create mode 100644 .gitconfig
# The following two lines just add an "upstream" purely for backup purposes.
$ git remote add origin /z/Backups/Dotfiles.git
$ git push -u origin master
<< snip >>
接下来我将以下内容放入$ HOME / .gitignore:
# First exclude everything.
*
# then re-include all "dotfiles"
!/.*
# then a bunch of specific excludes as they are more-or-less "cache" data rather than configuration.
/.bash_history
/.dbus-keyrings/
/.emacs.d/
/.gimp-2.8/
/.git/
/.gitk
/.idlerc/
/.lesshst
/.saves/
/.thumbnails/
最后,以下命令(道歉我没有捕获这些输出)将.gitignore本身添加到存储库:
$ cd $HOME
$ git add .gitignore
$ git commit -m "Added some rules so git status on the dotfiles is useful."
$ git push
现在,您添加到主目录的任何“普通”文件都会被dotfiles repo忽略,但任何新的dotfiles都会以git状态显示,例如:
$ cd $HOME
$ touch NewFile.txt
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
$ touch .funkychicken
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
.funkychicken
nothing added to commit but untracked files present (use "git add" to track)
到目前为止,这一直运行良好,即使一些子目录是他们自己的(不相关的)git存储库。有时会出现非git细分的“怪癖”,但到目前为止还没什么问题。
好吧,这是三年之后,没有人提出任何好的东西,所以我对这个问题进行了尝试。它是平台不可知的和shell无关的,除了你可用的bourne兼容shell(bash,zsh,ksh等)之外没有其他依赖项。它适用于mac,linux和windows:
它将使用github和多台计算机以及许多其他功能自动将更改同步到您的dotfiles。
我正在使用git repository(github)和bash脚本来创建符号链接。但现在我发现这个工具看起来更强大了。看看:https://github.com/shanx/python-dotfiles。
我找到了一种有趣的方法来使用普通的git来管理你的dotfiles,不需要符号链接。这样,你应该能够按常规方式进行推拉:
建立
git init --bare $HOME/.myconf
alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
config config status.showUntrackedFiles no
我的〜/ .myconf目录是一个git裸存储库。
用法
然后,通常的git命令可以与git别名一起使用,例如配置或您选择的任何内容。
config status
config add .vimrc
config commit -m "Add vimrc"
config push
优点
更多信息
您可以使用git push/pull
命令更新/同步您的dotfiles(GitHub充当“中央”存储库)。在谈到符号链接dotfiles时,我写了一篇关于它的文章。看看:manage your dotfiles with ease。
主要的想法是有一个单独的目录(通常称为.dotfiles),其中包含您想要在git中跟踪并在主目录中具有符号链接的所有真正的dotfiles。
这种方法已经做了很多工作,所以我建议你检查DFM(dotfiles manager):