+1 vote
1 view
in Devops and Agile by (22.3k points)

If I have a file or directory that is a symbolic link and I commit it to a Git repository, what happens to it?

I would assume that it leaves it as a symbolic link until the file is deleted and then if you pull the file back from an old version it just creates a normal file.

What does it do when I delete the file it references? Does it just commit the dangling link?

1 Answer

0 votes
by (38.3k points)
edited ago by

Git just stores the contents of the link in a ‘blob’(binary large object) just like it would for a normal file. Then it stores a symlink (which comprises of name, mode, and type) in the tree object that represents its containing directory.

When you check out a tree containing the link, it restores the object as a symlink regardless of the target file system object exists or not.

If you delete the file that the symlink references it doesn't affect the Git-controlled symlink in any way. So that’s up to you to change or remove symlinks.

Even if you removed symlink there is a dangling reference. So you can go ahead if you need to remove symlink.

For more information please go through the following tutorial to get more info about git:

...