WCG WCG - 3 months ago 14
Git Question

Can I add a file by putting the symbolic link in the git repository?

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

and have created a 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 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 filename 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.