How to copy a local git repository?

2

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

Analogously to databases, I do not think it is either correct to copy a .git directory, or even the entire directory of the project, for backup, or to carry on a thumb drive and download it at home.

So, what is the correct way to copy a repository git ?

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

    
asked by anonymous 17.04.2017 / 22:29

3 answers

2

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

You can export the repository to a zip file, for example, with the following command:

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

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

    
28.04.2017 / 19:03
1

I do not see why it would not work to copy the files, since there will be no concurrent access (and most files within .git are immutable anyway).

But if you want an alternative way, using git's own commands, you can do a simple git clone by passing the path of your original repository

So you will have access to several git clone options that you may 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. - see the git manual for details on each)

    
17.04.2017 / 23:33
0

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

    
18.04.2017 / 09:08