Search code examples
gitgit-pushgit-clonegit-remotegit-fetch

How to designate a local repository as a remote for another local repository?


In order to better understand how Git works, I'd like to inspect the changes that a remote repository undergoes as it interacts with a local repository (via fetch, push, etc.).

  1. Suppose I have two Git repositories, A and B, in my local file system. Is it possible to designate A as a remote repository with respect to B, so that, for instance all push commands performed in B will be pushed to A?

  2. Is it possible to clone a new local repository C from A using the clone command?


Solution

  • The answer to both your questions is: Yes!

    Use the Git commands as usual and pass the full or the relative path of the other repository as argument <repository>.

    For example, use:

    git clone ../repoA repoB
    

    to clone the repository ../repoA into the sub-directory repoB of the current directory.

    Read more about the ways to specify an URL in Git commands that require an URL of a remote repository.