Using git bundle create to backup repos to a specific directory? - linux

I am working on backing some git repos as part of a new back up plan. It seems git bundle is the way to go, but I am wondering, and in my, in all honesty, short google searches, I cannot seem to find out if I can do a bundle directly into a specific directory.
For my SVN I mounted a cifs share, and pointed the dump directly to that share without having to script a basic thing to create and then move.
Let me know, thank you.

Back-uping a git repository is as simple as either:
git clone --bare it to a new place. It allows to git push/pull for incremental backup.
tar -czf backup.tar.gz myrepo/.git/ file and copy it somewhere. So you can manage it in a simple file, easily.
It's easy.

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 prevent Git from storing copies of LFS files in .git dir?

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

Backup options for a project under version control with Git

I just arrived in a company which does not have access to GitHub or similar.
I was wondering about ways to backup my code using the private OneDrive which is given to each employee.
I just thought of moving my folder from the "document" directory to the "OneDrive" directory. But I was wondering whether changing the path will break my code.
Will it preserve the .git directory? Should I rerun git init (loosing the past history)?
You can move a Git repository from one path to another without affecting it. A Git repo is a self-contained entity (with the exception of global Git config) and the .git folder containing all Git files is just like any other folder (so it can be moved, deleted, etc.).
If you want to use OneDrive as a backup, there are better options than simply copying your project over. Tools like restic or similar would allow you to keep your backup up to date in an efficient way.
Note that you can also set OneDrive as a Git remote. Since it sounds like you are missing options such as GitHub or Bitbucket for your company, this is probably your best option.
To add a remote called onedrive on OneDrive, you can run:
git init --bare ~/OneDrive/<project>.git
git remote add onedrive ~/OneDrive/<project>.git
And then you can use onedrive as you would any other remote. For instance:
git push --set-upstream onedrive master

How could I recover my git-daemon repositories

I had a Gitorious install that got old and it is clear now that it is not coming back. I want to recover the repos (mainly the wiki repos) from the repository. I do not want to repeat the long and painful process of setting up Gitorious again, just to get some wiki back out of it...in fact I'd like to clean up the old install soon (remove it). Although, when it was running it was awesome!
I still have the database for gitorious, so I know which .git files I want and where to find them.
I was attempting to setup git-daemon (I'm on a Linux (ubuntu) setup), but I am not having much luck. I was hopeful that maybe I could just copy the 'foo.git' file somewhere and clone it.
Currently my .git files are in user git's home folder. No problem moving them though, but I'm not sure how to go about this.
I have git daemon running, but it 'hangs up unexpectedly' if I try to connect via 'localhost', all the repos also have my 'export-ok' file in them too. I can connect accross my LAN and clone any other git initialized directory via ssh, could that help me?
Can I just copy the foo.git (more like a f13f9ed412591ce72f7b3cb793605e93ce.git) file to maybe a git initialized repo and work with it there? Is there a git tool that I could use to expand the .git file? <-- I'm sure Git would be the tool right?
The .git is a folder and not a file and git repos are lightweight in that it is just files and folders. You can copy your repo to wherever you want.
Since you said localhost, if you want you can even clone the repos with git clone /path/to/repo.git and work on the cloned repo. You do not need the daemon or anything else to be running.

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