I have a new project I am working on and I already created a git repository for this project/directory. The project is on my machine in my office that is always running and reachable. Now I wanted to create a bare repository from it that I can use as a "server" to copy from/to from my home machine via ssh. I tried
git clone --bare project project.git
It created a bare repository from my working directory but there are no remotes or branches set to the new bare repo. But when I switch to the new repo
git remote -v
gives me
origin /home/auron/project (fetch)
origin /home/auron/project (push)
That's basically just the other way around than I wanted it. How can I achieve what I want?
[
git clone --bare
] created a bare repository from my working directory but there are no remotes or branches set to [make the original Git use] the new bare repo ...
That's quite normal.
When you make a clone, your Git remembers where it cloned from. It does not modify the source at all; it makes a new repository, more or less as if you ran the following sequence of commands:
mkdir new-repo.git
cd new-repo.git
git init <flags>
git remote add origin <url>
...
(where <flags>
represents the --bare
flag, and <url>
represents the URL from which you are cloning).
If you want to affect some existing repository:
cd existing-repository
git remote add <name> <url>
where <name>
is the name you want to use—maybe origin
, for instance—and <url>
is the URL you want to associate with that name.
Note that this merely adds a name, without first contacting the given URL to see if there is a Git at the given URL. So if you have a typo here your next git fetch
will fail, when it tries to use the URL.
Note also then when you make your initial bare clone, you may want to use the --mirror
option, if the source from which you are cloning has more than one branch. You may or may not want to run git remote remove origin
in the bare clone afterward, to remove from the clone its memory of where it came from. (In normal operation, remembering is harmless, but (a) if you used --mirror
and (b) someone tries to run git fetch
in the bare clone, this could be bad.)
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