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

I do not know how to make my requirement short in the title, sorry if that does not make sense. I will explain here:

Many people put their dotfiles on bitbucket or github to facilitate subsequent installation or configuration, synchronization on different computers. I did the same, but I want to do something special, I'm not sure how to help mecurial / git.

What I have:

I have 3 machines, for example Home, Office and Client, all Linux OS (there may be different distributions). To make the example simple, let's say I just want to put a single .zshrc file in a repo. The problem is that the three OSs have different system variables (or other settings). eg

  • Office has JBOSS installed, then in .zshrc I need to export JBOSS_HOME var.
  • The client installed Oracle and then exported a different set of vars.
  • Office should export HTTP_PROXY, but HOME isn’t, it also needs a client, but a different proxy value, etc.

Now, what I did, I extract these specific machine parameters (mainly export, alias expression) to another file, say myVar.sh . and enter it at the end of .zshrc .

So, 3 machines have a common part (the same .zshrc ) and different parts ( myVar.sh ).

What I want:

  • on any machine, if I find some good settings, I modify the .zshrc file (general part) and click. Changes should be easily synchronized with other machines (e.g. pull)

  • if I changed myVar.sh (the other part) in HOME and clicked, it should not affect Office myVar.sh if I click on Office.

What am I doing:

now I have one repo on a bitbucket and three branches (H, O, C). On a home PC, I just play with the branch "Home". The same for Office, Client.

The problem is that if I changed the common part on one PC, this change is in its own branch, a little difficult to synchronize with the other two. Because I will never merge these branches.

I also think of mk different directories for different computers. eg.

 /.zshrc |--/HOME/myVar.sh |--/Office/myVar.sh |--/Client/myVar.sh 

and write a shell script, for example. check $ HOST to decide to write myVar.sh to which directory. but I doubt if this is the best way to achieve my goal. And when I look at my point of view, I see all the settings of 3 pcs. I have to be careful and enter the correct one to read the file.

In the real world, the common part contains much more .zhsrc (tmux, vimrc, xdefault ..), as well as the other part.

I don’t know if we can somehow make a partial branch or do a partial merge in the repository ...

I use hg a lot more than git, if hg can solve it, I would prefer hg, if not, git is also valid. I have little git experience except clone, push, pull, up, merge, ci.

now how do i do ?

and thanks for reading this ...


EDIT more about another part

I would like to thank all the guys for the answers. As I said above, different parts of my real machines are not as simple as myVar.sh . For example, I take my laptop company (Office) for different clients (about 6 clients, not all clients provide us with a PC, this is good because I could work with Linux everywhere) and configured printers for each of the cups. I would put these configurations in Repo too. Because if one day I need to upgrade my system or a hard disk failure, I can configure these printers very simply. Other things that belong to another part, but I can’t just “source xxx”, for example

  • Xorg.conf for tracking
  • .hgrc (since in the company we have our own repo, uid, pwd, proxy ..)
  • some pre-configured systemd modules, mostly .conf files. But a specific machine, for example. radeon.conf is only for my home laptop. And the client PC is not installed on systemd at all.

    That is why I thought of different directories for PC.

As I said right now, I have three branches and have a myConf directory, in this directory I have getConf.sh to copy dotfiles, different confs, etc. in myConf . In fact, getConf.sh also belongs to another part, because the script is not the same for all PCs.

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

Yesterday I just took .zshrc and tried to make the example simple. If this fools you guys, sorry about that.

+4
source share
4 answers

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

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

It is supposedly even prettier in zsh, but the idea is that the host-specific file has a source at the end, and, of course, everything that is used on all machines goes mostly ~ / .bashrc.

+5
source

You can manage each setting in your branch as you do. You can add a submodule (repo to repo) that tracks common files for each. To sync them, you can

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

To configure, do the following:

in your home directory add the .gitignore file. Ignore everything with *. After this entry, exclude the point files that you want to save! .Ssh / for example.

Now it is easy to do it in a repo.

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

Now every change in .ssh / will be tracked. In your case, you can exclude .bashrc and .bash_profile if you want, or any other way.

Now you can simply follow the standard push and pull procedure from github or bitbucket (for free private repositories).

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

Now you have the settings on the server. Another car is on you:

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

The -t and -u options configure tracking so you can simply

 git push git pull 

when you need to get or save settings to / from the bitpack server.

Now, to sync your common repo part, you can read this short chapter on submodules at progit.org/book. see chapter 6 of section 6.

0
source

I had a similar problem, and I decided to fork it in the corresponding files.

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

 MAC=0 if [ -x "/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder" ]; then MAC=1 fi if [ $MAC -eq 1 ]; then export PATH=~/bin/:/sw/bin:$PATH else export PATH=~/bin/:/sbin/:$PATH fi 

If your .zshrc allows something like this, this might help. If not, I would use different files for each computer and update them separately (perhaps using a script to create these files based on some shared parts?).

0
source

Well, pure Mercurial-oriented solutions

  • Classic branching

Branch to the host, starting with the additional branch "vanilla" (there you save the common code). After that, in each branch you make host-specific changes. General changes (and only general ) should appear in the Vanilla branch and merge with the rest

  • MQ Patches

Single branch, target identical to Vanilla from p.1 ("changeets contain a common base"). All host-specific changed changes are stored in the mq-patch queue set (or, possibly, for the new Mercurial, in the queue). How to organize a patch stack is entirely your area of ​​responsibility:

  • You can use one queue and a full set of fixes for each host (separation by name), even if some different patches are clones of another. Result: simple operations to prepare the actual set of files for the host, you should apply all the NAME- * fixes
  • Functional separation: each patch serves for one task (BOSS, ORACLE, PROXY, PROXY-CONFIG ...). Result: fewer patches, logical uniting of files from blocks, expandable for a wider range of hosts without changing the internal logic.
  • Separate Queues: Each host has its own queue. Result: “foreign” patches will never be applied to the host, flaws are more complex (or impossible) patches for exchanging between queues, functional clones, as in the “full set” version (in fact, this is a change in the “full set” with a stronger separation )
0
source

All Articles