How to copy a local git repository?

Asked

Viewed 856 times

2

It is already common knowledge that it is not good practice directly copy the physical files (mdf, etc.) from the database. Therefore, there are specific routines that generate external files that can be imported.

Similarly to databases, I believe it is also not correct to copy a directory .git, or even the entire project directory, for backup, or to carry on a USB stick and download at home.

So what’s the right way to copy a repository git?

It is important to assume here that it is a local repository, not remotely hosted in services like Github.

3 answers

2


There is a git command for this, called git archive.

It is possible to export the repository to zip file, for example, with the following command:

git archive --format zip --output zipfile.zip master 

For more details, you can consult the documentation via git help archive.

1

I don’t see why it wouldn’t work to copy the files, since there won’t be any concurrent access (and most of the files inside the . git is unchangeable even).

But if you want an alternative way, using commands from git itself, you can make a simple git clone passing the path of your original repository

Then you’ll have access to several options of git clone that you might find useful for your copy (examples of some that I found interesting: --local/--no-local, --no-hardlinks, --bare, --depth, --single-branch/--no-single-branch, --recursive etc. - refer to the git manual for details about each)

0

A Git repository is based on source files, or any other type, plus a hidden folder . git, as is a DVCS, Each repository has not only the data (code) but the history information, it is in this hidden folder that all the information about the repository, history, branchs, tags, etc... Therefore, you can move it, copy it without losing information. But you should do it from root folder.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.