4

I set myself up a dotfiles repo, hosted on a remote server and used on different machines. For some things I'd like to have individual configurations, e.g. the environment variables differ between machines.

I thought, it would be nice to have an extra branch for the machine-dependent changes, so for example I have the branches server, notebook, desktop, all based on master with little individual changes (1 to a few commits). Now the problem is, I want to have those individual changes applied on top, obviously. So I'd alter master for common changes and rebase the local desktop branch upon that. But using rebase, I can't push to the remote repo anymore. And I want that, as backup and for syncing, obviously, and it also might happen that I want to alter the branch of machine A while actually working on machine B.

Is it at all reasonable to maintain a single branch for every machine or is there a better solution? How would I be able to apply the local changes on top, as with rebase, but not losing the ability to push? Thanks very much

j. doe
  • 41
  • 2
  • Would it be an option to store all machine-dependent variable in a single file, and have a git hook propagate the values when necessary? – Arcturus B Apr 29 '16 at 08:29

2 Answers2

2

Your multiple branches approach sounds reasonable, and is the solution of some issues I was having with machine specific scripts (work/personal).

The problem you're describing is that you cannot push changes after doing a git rebase.

The reason you can't push is because git rebase rewrites history. It removes your branch specific commits, syncs with master and reapplies the commits on top:

enter image description here

Why not merge instead of rebase?

By merging (git merge master) you won't rewrite history and you won't have problems pushing to your remote.

I recommend you read this article, it explains the difference between merge and rebasse.

If you really need/want to rebase, you'll have to force push your changes to your remote by running git push --force <remote_name> <branch_name>

Maximo Dominguez
  • 2,075
  • 18
  • 35
0

You can also include files in your gitconfig

[include]
   path = ~/my_std_git_config

So you could have one common file with standard stuff. And several gitconfig files for your different hosts.

Then link only one of the host specific gitconfigs to ~/.gitconfig . Keep all files together in one branch.

i.E. in your repository:

common_gitconfig
laptop_gitconfig
server_gitconfig

Include common_gitconfig into laptop_* and server_* . Link your laptop_gitconfig to ~/.gitconfig on your laptop. On your server link server_gitconfig.

hewo
  • 786
  • 1
  • 8
  • 17