Is there a way to push a file external to the git repository by putting a symbolic link.
I want for instance to push the file /root/my_file
and have created a symbolic link my_symbolic_link
in the git repository.
# ls -lA
drwxr-xr-x 7 root root 4096 Oct 8 07:55 .git/
lrwxrwxrwx 1 root root 26 Oct 8 7:58 my_symbolic_link -> /root/my_file
Symbolic link is a file that contains a reference to another file in your filesystem. You can add symlink to your repository, but by doing it you are only adding reference to other file and not that other file.
You can achieve what you want by creating hard link instead of symbolic link. Hard link is association between name of the file and its content (and metadata) on file system level. By creating hard link to a file and adding it to your repository, you are adding that linked file. On POSIX-compliant operating systems (like all the linuxes) you can create hard link like this:
ln /root/my_file my_hard_link
For more info about different kind of links see this question and its answers.
UPDATE: Please note that git doesn't know anything about hard links. Adding hard link to git repo means that you are adding content of that linked file. Git doesn't know that the file you've just added is a hard link. Adding hard link to repo won't break it, but checking it out of the repo will create a new copy of that file, and won't recreate that hard link. By "checking it out" I don't mean only git checkout
command, but also operations like clone
ing a new copy of the repo, deleting hard link and using git reset
to recreate it, or pull
ing new version of this hard linked file from remote repo.
To recap - your two options are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With