问题
Take a Git repo named myrepo
. What is it's real name/filename when referring to it as a remote?
I ask because I've noticed that for Github you can use either:
https://github.com/lightcc/myrepo
https://github.com/lightcc/myrepo.git
I've also seen cases where local repos point directly to the .git
folder:
/c/code/myrepo/.git
And other cases where the repo is locally called by the repo folder name like myrepo.git
, such as:
/c/code/myrepo.git
That last one might be the real folder name for a --bare
repo, but I'm not sure, I haven't created a local bare repo before.
So what is the correct name to use when trying to setup a remote (i.e. what name is correct to use in a git remote add
statement)?
Edit: Updated question as the answers weren't what I expected - I am trying to understand how to setup a repo as a remote, or even setup a local repo properly so that it can become a remote in the future. So this has more to do with the git remote add
command syntax. I get that in English we would just say it is named myrepo
.
回答1:
It depends on the server.
GitHub and others will alias the non-.git
version to .git
.
If you're running your own Git server, and name the bare repository with .git
(as recommended for bare repos), then you will be required to use .git
.
回答2:
What is its real name/filename when referring to it as a remote?
When referring to a repository as a remote, the URL at which the remote repository is reachable does not actually matter. What matters then is the name you give it when adding the remote:
git remote add <remote-name> <remote-url>
You can choose really any name there. Two common names which kind of have their own inherent meaning (although that’s not a rule) are origin
for the default remote you cloned from and usually pull from or push to, and upstream
for an upstream repository that your origin
is a fork of (so usually, the workflow would be pull from upstream
, do work, push to origin
and send pull request).
As for the URL, this really depends on what kind of system you are interacting with: In general, the URL has to be valid. For file systems, this means that the path must exist. So /path/to/repo.git
and /path/to/repo/.git
would be two very different things.
In general, the .git
folder has a name, when its a bare repository (a repository without a working directory). In that case, the repository name is the name before the .git
. So for /path/to/repo.git
, repo
would be the name.
When it’s just /path/to/repo/.git
, then we’re dealing with a non-bare repository and the working directory is at /path/to/repo/
. Its name would also be repo
.
For actual URLs, it’s up to the server to decide what to accept, whether they require a .git
extension or not. Most repository hosters (like GitHub and Bitbucket) will accept either, so just choose whatever you like (or whatever the web UI puts into your clipboard when you click “clone”).
来源:https://stackoverflow.com/questions/46302762/what-is-a-git-repositorys-real-name-when-defining-a-remote