When working with Git in Android Studio, the following problem occurred:

I would like to add a local repository, for example, on a flash drive. Ie, I want to clone a project from one local repository (on a PC) to another (on a flash drive) (for example, so that if something happens to a PC, you can take this project from a flash drive). In this case, then when making changes to the project, it is necessary that each of the repositories can be updated.

There is a lot of information on the Internet about how to do this for servers, i.e. clone the current repository with the project, for example, in GitHub.

And how to do it for a local repository? How can I clone a project from one local repository to another in Android Studio?

The contents of the config file in the .git folder that is created after cloning into the local repository:

[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly [remote "origin"] url = D:\\workDinar\\Android\\GitExperiment fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master 
  • one
    Briefly: bare-repository on a flash drive, git remote add backup path/to/repo , - Nick Volynkin
  • @NickVolynkin, thanks for the reply. With the command line, everything seems to be clear. Is it possible to do this using the built-in tools of Android Studio? - foxis
  • unlikely, did not come across. - Nick Volynkin
  • one
    If a studio is cloned onto a local media according to a scheme, like a remote one, but specifying a path on a disk instead of a URL, then for some reason only the folder /.git is cloned, and the whole project (the files themselves) is not cloned (the same with the clone command from VCS -> Git -> Clone ), at least I did not succeed, but perhaps the truth is somewhere near - pavlofff
  • one
    @pavlofff, foxis, judging by the contents of the .git/config file laid out in the question text, everything is in order with the repository. well, if android studio doesn’t do git checkout after cloning, then this is just a “bug” of this program that should be reported to the developers. - aleksandr barakin

1 answer 1

You can clone a local repository, like a remote one, with an absolutely standard command:

 $ git clone url-репозитория 
  • in unix-like operating systems, the url repository is simply a repository path: /путь/к/каталогу/.git or even without the last part: /путь/к/каталогу .
  • in non - unix-like operating systems it is a bit more complicated : the url repository should probably look something like: file:///C:/путь/к/каталогу/.git (or file:///C:/путь/к/каталогу ).

I assume that exactly the same thing can be done not only in the android studio program, but also in any other program capable of executing the git program with the clone command and the required parameters. you just need to specify the correct url repository .


update

Here is a manual with pictures , which buttons in android studio should be clicked to clone an arbitrary repository. I will bring pictures here for safety:

enter image description here

enter image description here

enter image description here

  • I meant that the studio is not able to create bare-repository. - Nick Volynkin
  • @NickVolynkin, I understand you. Yes, the normal scheme in the presence of two or more clones is to clone them not from each other, but from a bare-clone. but at first the author of the question, in my opinion, is better not to bother with such information. However, for other readers, it is probably better to mention this moment. you do not remember, maybe we already have an answer here in which such a scheme is chewed? - aleksandr barakin
  • one
    @foxis, the answer is written including about android studio . in the last paragraph. If Android Studio does not have a normal toolkit in this case, I’ll rather use sourceTree - formally, its (toolkit) is neither there nor there. because both of these programs use the git program (in the form of an executable file or library). but both are great at doing git clone , which is what you need. so (with some degree of conditionality) it can be said that both programs mentioned by you have a “suitable tool”. - aleksandr barakin
  • one
    @foxis, you tell me all the time to use the command line — I don’t see where I told you that. and in the GUI this is normally not implemented - yes it is implemented, of course! there you have about cloning, with pictures . Only specify the repository url correctly, as written in the answer. - aleksandr barakin
  • one
    Unfortunately, @foxis cannot: I don’t have not only android studio , but even ms / windows . As far as I understand, in the specified directory you create a sub-directory .git (with the contents of the repository), and more files / directories are not created? Please attach to the text of the question the contents of the .git/config file that is created when attempting to clone. This is a simple text file. - aleksandr barakin