Suppose I have cloned a Git repository to my local disk using:
git clone [email protected]:someproject.git
Now suppose that git.example.com
is not being backed up, and it goes down in a blaze of glory. Does my clone contain everything necessary to rebuild the remote repo that was lost? The Ultimate Backups section of Git Magic suggests that the answer is "yes," but it isn't clear to me.
Note that I'm not asking "is my local clone a sufficient backup of the master
branch?" I'm asking whether my local clone can be considered a complete backup of everything that was contained in the remote repo; all branches, all tags, everything. For example, what about remote branches that aren't tracked in the local repo?
To futher confuse the issue, the existence of git clone --mirror
suggests to me that my local clone should not be considered a complete backup of the remote repo.
By cloning with Git, you get the entire repository - all files, all branches, and all commits. Cloning a repository is typically only done once, at the beginning of your interaction with a project.
When you clone a repository, you copy the repository from GitHub.com to your local machine. Cloning a repository pulls down a full copy of all the repository data that GitHub.com has at that point in time, including all versions of every file and folder for the project.
You can use Sourcetree, Git from the command line, or any client you like to clone your Git repository. These instructions show you how to clone your repository using Git from the terminal. From the repository, select the Clone button. Copy the clone command (either the SSH format or the HTTPS).
A clone can be considered a full backup of all the data in your remote repository, but not necessarily the meta-data (that's where the --mirror
switch comes in). Your clone will contain all the commit, tree, blob, branch, and tag objects that are in any way referenced by the repository. That means your backup will contain all your source code, history, and associated branches or tags.
The difference with the --mirror
switch is that without it, the clone won't include things like remotes that have been created on the server. These are not important in a "I hope I haven't lost any source!" kind of way, but they may be for getting your server back up and running like it was.
If you're interested in creating a backup that can be restored onto the server like there was never any issue, then you should use --mirror
, but for most scenarios a simple clone is fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With