How to prevent Git from storing copies of LFS files in .git dir? - gitlab

It seems that Git is storing copies of LFS files in .git/lfs. This is taking twice of the space. I know this is a typical way Git handles the files, but I'm still wondering if there is a way to prevent Git from caching copies of them and just download from cloud when trying to revert the files.

If the files are in the lfs folder, it's that git needed them at a moment to populate your working directory.
So, no, there is no way to prevent git to cache them (except maybe by doing a sparse checkout if you really don't need to have the files handled by git-lfs in your working directory).
But you have an easy way to clean this cache directory (git will keep only the currently used files and delete the others unused) with the command:
git lfs prune

Related

How can I add a .git directory to a git repository?

I am doing unit tests on a python program who, for QA purposes, gets the repository name and the current commit hash from the .git in the directory
For my unit tests on that program I would like to have a dummy .git directory in the tests directory. That .git repository would have a single initialization commit and a remote that would not be used
When attempting to add a .git to my tool's repository, git seems to ignore it and indicates that there are no differences in the status and commit
How can I add the .git directory to my project repository ? Something like tests/.git
You can't do that. It's inherently forbidden by Git.
You can store a tar or ZIP archive that contains the repository, and then have your test routine extract it to a temporary location. If you go that route, I recommend to use an uncompressed archive format, because it allows Git's own compression algorithms to work more efficient.
I think we would need more details about what you want to achieve to provide like the best answer... but I think you should look at git bundle. You can track a bundle file and then use it to regenerate a git repo.

How to push shared files (header/source) from outside a Git repository to it?

I've developed two small programs, both of which include my_lcd_lib.h and my_lcd_lib.c.
To prevent code duplication I moved this "lib" from the include folder in each project to /usr/local/include. So far, so good.
How could I tell Git to include those files when pushing the repo?
So the repos from Prog1 and Prog2 would have their own copies of the header/source files.
I can imagine three ways:
When pushing the program repo from dev pc to gitlab server, git could include those outside files by some tricks. Maybe need to edit some .git* files?
I could make a lib-repo for the stuff in /usr/local/include. I could set up my program repo to load the appropriate files from the lib-repo. Is that what the pipe/cli are meant for?
I could copy the header files from /usr/local/include to the program repo just before pushing the program repo. This looks very unsexy.
No, you cannot push files outside the repository. Git does not push individual files, it pushes commits. The files have to part of a commit.
Once you've committed those files in your repository, the rough solution is to symlink them into /usr/local/include/. The better solution is to used a build tool like autoconf and install them in /usr/local/include.
Git is not a substitute for a build tool, nor dependency manager, nor installer.

git-annex use a file from a different location

My understanding is that when I perform git annex add somefile, it creates a symlink for that file and places it in the .git/annex/objects folder. Then, when I initialize git-annex in some different location and sync it with the previous one, it downloads a broken symlink, unless I do git annex sync --content, which makes a full copy of the file.
I need to have large files in one location, lets say on a USB Drive, and multiple git repositories that use the large files. So I want to have just the symlinks to the large files in those git repos. How to perform the sync so git-annex downloads a valid symlink that points to a file in a single location ?
There are two ways to do that.
First is using hard-links, second is using symlinks. I recommend hard-links if all your files are going to be in the same filesystem/volume/partition, otherwise the good ol' cp --link is just going to copy the entire thing.
Using hard-links:
git clone --shared main_repo/ new_repo/
Explained by git-annex author himself
Using symlinks:
On main_repo:
git worktree add -b branch_name path_to_new_repo/
Since git-worktree uses a pointer file (which git-annex replaces with a symlink), this will work across different file systems. Changes to "different repos" will be stored in different branches. If you want them all to remain in sync, keep them in sync with standard git commands like git merge. Or you could only make changes to the master branch and git rebase master from the different branches frequently.

How to conveniently sync a file between two git repositories

I have two git local repositories. Both share an identical file, under a different path and under a different name. Currently, when I make changes I have to copy the file from one directory to another.
Is there an alternative way to keep them in sync without manually overwriting the file? I don't want to create a separate repository for this file. I thought one of the following things would work, but apparently, they don't:
git submodule
git subtree
symlink soft
symlink hard
What else is there?
The only other alternative would be a post-commit hook on repoA, which would, on each commit:
check if the file is part of said commit
copy it in repoB with the right path.

Exporting files from hook in bare git repository

So, my situation is the following: I want to maintain my website using emacs-muse mode. For transferring the website (and version control), I want to use git. So I would create a hook in the remote (bare) repository that automatically copies the HTML subdir to the web directory. How can I do that from a hook? Also note that the whole directory contains a lot of files, so I can't export the whole directory.
Any help welcome.
You can use git archive, as it takes a path command. So, in your post-update hook you can do something like
git archive $SHA HTML | (cd dir/where/html/should/go && tar x)
this first creates a tarball of the subdir, and pipes that tarball to a tar command to untar it in the specified directory
(just a suggestion, as it may not be applicable in your exact configuration)
You might consider adopting this Web-Focused Git Workflow which, instead of copying, does push your repo directly on the web directory.
(From Joe MALLER)
Less complicated: Using Git to maintain your website (Daniel MIESSLER):
Daniel MIESSLER has an updated version of that same process:
Other suggestions are available at this SO question, like this post-update script mentioned in the Git FAQ.

Resources