Can a local Git clone be considered a full backup of the repo from which it was cloned?

Suppose I cloned a Git repository to my local drive using:

git clone username@git.example.com:someproject.git 

Now suppose git.example.com not reinforced, and it falls in glory. Does my clone contain everything needed to recover a deleted repo that was lost? The Ultimate Backups Git Magic section suggests that the answer is yes, but this is not clear to me.

Please note that I am not asking: "Is my local clone a sufficient backup of the master branch?" I ask if my local clone can be considered a full backup of everything contained in the remote repo; all branches, all tags, everything. For example, what about remote branches that are not tracked in the local repo?

To confuse the issue, the existence of git clone --mirror tells me that my local clone should not be considered a full backup of the remote repo.

+43
git
Jan 11 2018-11-11T00:
source share
3 answers

A clone can be considered a complete backup of all the data in your remote repository, but not necessarily metadata (where the --mirror switch is --mirror ). Your clone will contain all the commit, tree, blob, branch, and tag objects that refer to the repository in some way. This means that your backup will contain all the source code, history, and related branches or tags.

The difference with the --mirror switch is that without it, the clone will not include objects such as remote ones created on the server. It doesn’t matter in "I hope I have not lost the source!" but they can be for the recovery and operation of your server, as it were.

If you are interested in creating a backup that can be restored on the server, as there have never been any problems, then you should use --mirror , but for most scenarios a simple clone is fine.

+46
Jan 11
source share

Your local clone will not be a full backup. This will be a backup of the state of this repository, but it will not have all the links of the original repository (therefore, it will not know about the status of any remote branches).

For a full backup, you correctly found git clone --mirror . This will not only be branches for the source repository. It will also display all links, including remote branches.

+4
Jan 11 2018-11-11T00:
source share

IMPORTANT

Without --mirror , the clone will not be a full backup. Any line not displayed in git branch -r will be removed from the clone.

Simple demonstration

Witness a simple repo.

 $ git init G $ cd G $ for f in 1 2 3 4; do date >1 && git add 1 && git commit -m $f; sleep 1.1; done $ git log --oneline --graph --all --decorate * 3c111bd (HEAD -> master) 4 * a08fea4 3 * d5c8d73 2 * 802856b 1 

Add thread:

 $ git checkout d5c8d73 HEAD is now at d5c8d73... 2 $ git branch starts-at-2 $ git checkout starts-at-2 Switched to branch 'starts-at-2' $ for f in 1 2 3 4; do date >1 && git add 1 && git commit -m 2-$f; sleep 1.1; done $ git log --oneline --graph --all --decorate * 6bb05bf (HEAD -> starts-at-2) 2-4 * fe1b635 2-3 * a9323fb 2-2 * 33502af 2-1 | * 3c111bd (master) 4 | * a08fea4 3 |/ * d5c8d73 2 * 802856b 1 

Clone the repo.

 $ cd .. $ $ git clone G G2 Cloning into 'G2'... $ cd G2 $ git log --oneline --graph --all --decorate * 6bb05bf (HEAD -> starts-at-2, origin/starts-at-2, origin/HEAD) 2-4 * fe1b635 2-3 * a9323fb 2-2 * 33502af 2-1 | * 3c111bd (origin/master) 4 | * a08fea4 3 |/ * d5c8d73 2 * 802856b 1 

Fine Clone again.

 $ cd .. $ git clone G2 G3 $ cd G3 $ git log --oneline --graph --all --decorate * 6bb05bf (HEAD -> starts-at-2, origin/starts-at-2, origin/HEAD) 2-4 * fe1b635 2-3 * a9323fb 2-2 * 33502af 2-1 * d5c8d73 2 * 802856b 1 

Urk.

0
Nov 22 '17 at 13:27
source share



All Articles