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 :
git init --bare
And now exclusively on local folder my_project with the existing repo :
git remote add origin url_to_my_project.git
git push -u --all
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.
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 usinggit branch -a
command, I have two different results,
That is expected:
The git push --all
does push all branches under refs/heads
/
The -u
part adds upstream (tracking) reference, used by argument-less git pull
and other commands.
git branch -a
on your second clone does list the symbolic branch referenced by your remote repo.
origin/HEAD
represents the default branch on the remote repository you just cloned.
Something that the first repository (you pushed) couldn't know, since you were pushing to an empty repository (no default branch yet)