Partial branch or partial merge or other way to help me to sync dotfiles?

I don’t know how to make my requirement short in title, sorry if it is not meaningful. I will explain here:

Many people put their dotfiles on bitbucket or github, to ease later installation or configuration, sync over different pc. I did the same, however I want to do something special, I am not sure how mecurial/git could help.

  • How to use Github to manage dotfiles?
  • One git for multiple folders in differents places
  • Avoiding merge conflicts when merging master into per-host customized branch
  • Setting up DotBot & Antigen
  • How can I grep hidden files?
  • Homesick with bash-it as submodule
  • What I have:

    I have 3 machines, say Home, Office and Client, all linux OS (could be different distributions). To make the example simple, say I just want to put one file the .zshrc into repo. The problem is, the three OS have different system variables(or other settings). e.g.

    • Office has JBOSS installed, then in .zshrc I need export JBOSS_HOME var.
    • Client has Oracle installed, then export different set of vars.
    • Office has to export HTTP_PROXY, but HOME not, Client needs it too, but different proxy value etc.

    Now what I did is, I extract those machine specific settings (mostly export, alias statement) to another file, say and source it at the end of the .zshrc.

    So 3 machines have common part (same .zshrc), and different parts (

    What I want:

    • on any machine, if I found some nice settings, I change the .zshrc file (common part) and push. The changes should be easily sync to other machines (by pull, for example)

    • if I changed the (different part) on HOME, and push, it should not affect Office’s if I do pull on Office machine.

    What I am doing:

    now I have one Repo on bitBucket, and three branches (H,O,C). On Home PC, I just play with Home branch. Same for Office, Client.

    The problem is, if I changed the common part on one pc, the change is in its own branch, a little bit difficult to sync to the other two. Because I would never merge those branches.

    I also think about to mk different directories for different pc. e.g.


    and write shell script, e.g. check $HOST to decide writing to which directory. but I doubt that if it is the best way to achieve my goal. And when I look my dotfiles dir, I see all 3 pcs’ setting. I should be careful and enter the correct one to read the file.

    In real world, the common part contains much more than .zhsrc (tmux,vimrc,xdefault..), so does the different part.

    I don’t know can we somehow make a partial branch or do a partial merge on a repository…

    I use hg much more than git, if hg can solve it I would prefer hg, if not, git is also acceptable. I don’t have much git experience except for clone, push, pull, up, merge,ci.

    now, how should I do?

    and, thank you for reading this…

    EDIT more about the different part

    I would thank you all guys for giving me answers. As I said above, the different part in my real machines is not as simple as For example, I take my company-laptop (Office) to different clients (There are about 6 clients, not all clients provide us PCs, it is good because I could work with Linux everywhere), and configured printers for each by cups. I would put those configurations in Repo too. Because if one day I have to refresh my system, or harddisk failed, I could setup those printers very easy. Other things that belongs to different part but I cannot simply “source xxx” like

    • Xorg.conf for trackpoint
    • .hgrc file (since in company we have our own repo, uid, pwd, proxy..)
    • some pre-configured systemd modules, basically .conf files. But machine specific, e.g. radeon.conf only for my Home laptop. And Client pc has no systemd installed at all.

      That’s why I thought about different directory for PCs.

    As I said right now I am with 3 branches way, and have a myConf directory, within this directory I have, to copy dotfiles, different confs etc to myConf. In fact the belongs to different part too, because the script is not same for all pcs.

    Therefore I think the if-else/switch then source may not work in this case.

    Yesterday I just took the .zshrc, and try to make the example simple. If it mislead you guys, sorry about that.

  • git workflow with multiple, different remotes
  • Need to understand Git/Gerrit command (fetch & push)
  • Merging feature branches with several authors
  • Switching branches with IntelliJ & Git
  • Git merge/cherry-pick issue
  • Can I share an entire Git project via Gist?
  • 4 Solutions collect form web for “Partial branch or partial merge or other way to help me to sync dotfiles?”

    My preferred way to do this is to have a host-specific version for each file all in the same directory — similar to your same file multiple directories, and then include it via variable interpolation in my main file. So ~/.bashrc has inside of this this:

    if [ -f ~/.bashrc-$HOSTNAME ] ; then
         source ~/.bashrc-$HOSTNAME

    Presumably that’s even prettier in zsh, but the idea is if a host-specific file exists source it at the end, and of course anything that applies on all machines goes in the main ~/.bashrc itself.

    You can manage each setting in it’s own branch as you are doing. You can add a submodule (a repo within a repo) that tracks the common files across each. To sync them up, you can

    git checkout otherbranch -- path/to/common/script && git submodule update

    To get setup, do this:

    in your home directory add a .gitignore file. Ignore everything with *. After that entry, exclude the dot files you want to keep with !.ssh/ for example.

    now making this into a repo is easy.

    git init repostart
    mv repostart/.git .
    rm -rf repostart
    git add .gitignore .ssh
    git commit -m "initial start of syncing my settings"

    This will now track every change in .ssh/. In your case, you can exclude .bashrc and .bash_profile if you like or any other path.

    Now you can just follow standard procedure of pushing and pulling from say github or bitbucket (for free private repos).

    git remote add origin <url to bitbucket repo>
    git push -u origin master

    now you have the settings up on the server. On you other machine:

    cd ~
    git clone <path to your settings> settings
    mv settings/.git . 
    rm -rf settings
    git pull origin master -t

    The -t and -u options set up tracking so you can just

    git push
    git pull

    when you need to get or save setting to/from the bitbucket server.

    Now to get your common part of the repo in sync, you can read this short chapter on submodules in see chapter 6 section 6.

    I had a similar problem and solved it by branching in the corresponding files.

    Here’s a small example showing how I exported different PATH values for my Mac and my other computers (inside .bashrc):

    if [ -x "/System/Library/CoreServices/" ]; then
    if [ $MAC -eq 1 ]; then
      export PATH=~/bin/:/sw/bin:$PATH
      export PATH=~/bin/:/sbin/:$PATH

    If your .zshrc allows something similar, this might help. If not, I’d use different files for each computer and update them individually (maybe with a script generating these files based on some shared parts?).

    Well, pure Mercurial-centric solutions

    1. Classic branching

    Branch per host, started from additional “vanilla” branch (there you’ll store shared code). After it in each branch you perform host-specific changes. Common changes (and only common) have to appear in Vanilla branch and merged to the rest

    1. MQ patches

    Single branch, purpose identical to Vanilla from p.1 (“changesets contain common base”). All mutable host-specific changes stored in set of mq-patch’s queue (or, for fresh Mercurial, in queues maybe). How to organize patch-stack is fully your area of responsibility:

    • You can use one queue and full set of patches for every host (name-based separation), even if some different patches are clones of another. Result: easy operations for preparing actual fileset for host, you have to apply all NAME-* patches
    • Functional separation: every patch serve for single task (BOSS, ORACLE, PROXY, PROXY-CONFIG…). Result: less patches, logical combining of files from blocks, expandable for wider hosts-set without changing internal logic
    • Separate queues: Each host have own queue. Result: “foreign” patches never will be applied to host, drawback – harder (or impossible) patches exchange between queues, functional clones as in version “full set” (really it’s variation of “full set” with stronger separation)
    Git Baby is a git and github fan, let's start git clone.