Kinxil
Kinxil

Reputation: 321

Centralized Git repository starting from local

Suppose I want to settle a Git repository with an SVN like workflow (so a centralized repository on an URL every developer refers to).

I understood that you can push to Bare repository without restrictions (but group rights and the likes), but you can't on a regular one without using force option. So a "SVN" like central repository should be initialized bare. Did I understood that properly ?

Now, I wonder what is the shortest way to generate a centralized repository out of a local folder which already has a git repository (with no clone nor remote link yet), sources files, and possibly with more than 1 branch.

For now I use the following method, but I'm not sure it's enough :

On the remote folder my_project.git :

And now exclusively on local folder my_project with the existing repo :

Is this enough ?

When I clone the centralized repo on another local place, the new repo does not seems strictly equivalent than the original local copy. When using git branch -a command, I have two different results, and my git knowledge is currently not enough to understand what happened.

On original local repository :

> git branch -a
* master
  remotes/origin/master

On local repository cloned from centralized remote :

> git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

What exactly happened that the two copies doesn't look equivalent ?

Thanks in advance.

Upvotes: 2

Views: 993

Answers (2)

snipsnipsnip
snipsnipsnip

Reputation: 2585

Branches on the remote repository are renamed like remote/<remote-name>/<branch-name> on local copy (by default) to avoid name conflict between local and remote repositories.

If you want a SVN-like behavior (i.e. share the same branch namespace), you can edit the mapping on .git/config to your need:

# default configuration ('master' branch on remote corresponds to 'remotes/origin/master' branch on local)
[remote "origin"]
    url = [email protected]:example/url_to_my_project.git
    fetch = +refs/heads/master:refs/remotes/origin/master

For example:

# SVN-like configuration ('master' branch on remote corresponds to 'master' branch on local)
[remote "origin"]
    url = [email protected]:example/url_to_my_project.git
    fetch = +refs/heads/master:refs/heads/master

That said, it is not a recommended nor scalable way since you need to configure this mapping on each clone of the repository.

See the refspec section on the Git Book and related Q&A for more details.

Upvotes: 1

VonC
VonC

Reputation: 1324557

So a "SVN" like central repository should be initialized bare. Did I understood that properly ? Pushing to a bare repository (without any working tree checked out, which might be impacted by the push) is the best practice.

git init --bare; 
# local: 
git remote add origin url_to_my_project.git
git push -u --all

Is this enough ?

Yes.
Provided you have a listener: ssh daemon (as mentioned in "Getting Git on a Server") or HTTPS server (used for smart HTTP)

When I clone the centralized repo on another local place, the new repo does not seems strictly equivalent than the original local copy.
When using git branch -a command, I have two different results,

That is expected:

Upvotes: 2

Related Questions