Assume I have local workstation with root access and a server without root access. I want to share (mostly configuration) files between these two computers. So I set up a git repository with top-level in my home directory and add these files. So far so good.

Further assume that there exists a file that I need on both computers. It comes with the package manager and as such will be installed outside my home directory. It is not installed on the server and it won't be installed on the server. I now have two options:

  1. I install it with the package manager locally and install it on the remote server by hand. This way the files are not in sync. That's somewhat okay, since the file comes from the package manager, it's not really a file I'm working on. However, I always need to install it separately when moving to a new server, and this happens frequently. I could add a shell script that installs the package and add this shell script to the git repository, though.

  2. I install it locally in my home directory and add it to the repository. This way I don't have to install it separately on different machines, it is kept in sync, but it is not updated anymore through the package manager. That's what I'm doing right now.

And here's the question: Is there a third - better - way how to do this? any git symbolic link magic?

closed as primarily opinion-based by Thomas Dickey, HalosGhost, countermode, GAD3R, polemon Nov 6 '16 at 11:52

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.


From your description, I took it that you wanted to run the shell script on the remote machine. But perhaps it would be more convenient to set up a shell script to run just on your local machine, pushing the package from your local package-directory into your local git repo. Then you could use cron or, neater still, a git commit hook, to run this script so that you're always in sync.

[Moved from comment to answer on request]


I'm using the following pre-push hook now:

#!/usr/bin/env bash

# Copy local files that are outside the repository (because they are controlled
# by the package manager) into the repository and commit them
# Although this is a pre-push hook, the files are not included in this push
# See also: http://unix.stackexchange.com/q/321328/58056



echo "Execute git pre-push hook"

for idx in "${!localFiles[@]}"; do 
    echo -n "Copy ${localFile} to ${remoteFile}... "
    cp "${localFile}" "${remoteFile}"
    echo "Done."
    echo -n "Add ${remoteFile} to repository... "
    git add -f "${remoteFile}"
    echo "Done."

echo "Commit if there is anything to commit... "
git commit -m "Automatically add files by git pre-push hook" \
    && echo -n "Some files were added and commited (but not pushed) " \
    && echo "by the git pre-push hook"

# Don't interfere with the push, so always exit with success
exit 0

Not the answer you're looking for? Browse other questions tagged or ask your own question.