A Git project commonly consists of three main sections in a Developer environment and a single section in a Git Server:
.git] git==>stage[Staging Area] git==>work[Working Directory] end
In order to “move” a git repo to a git server, a special directory has to be generated first. This is called a bare repository, a directory that only contains the git data but not the project source code files, just like the .git directory.
Then this bare repo should be moved to the server, so the server acts as a common git server.
The repo from which the server was generated needs to add the git server as a remote and every other developer that wants to work in that project can clone it from the server directly.
An alternative workflow that does not involve cloning the repo locally would be:
Log in to the remote server
Create an empty bare repo:
mkdir /srv/git/my_project.git cd /srv/git/my_project.git git --bare init CTRL-d
Back in local host, add the remote:
git remote add origin firstname.lastname@example.org:/srv/git/my_project.git
git push origin master
Create bare repository
In order to set up a Git server, you have to export an existing repository
into a new bare repository (a repository that doesn’t contain
a working directory). This can be done with
--bareMake a bare Git repository. That is, instead of creating _directory_ and placing the administrative files in
_directory_/.gitmake the _directory_ itself the
$ git clone --bare my_project my_project.git
Cloning into bare repository my_project.git...
Copy repo to remote server
Put the bare repository in the server.
$ scp -r my_project.git email@example.com:/srv/git $ rm -fr my_project.git
Add server repo as a remote in local repo
After having the repo in the remote server, the git server remote should be added to the local repo so it is possible to pull and push changes to it.
$ cd my_project # Set a new remote (my_project)$ git remote add origin firstname.lastname@example.org:/srv/git/my_project.git
git remote add origin ssh://email@example.com:2222/srv/git/my_project.git
Verify new remote
(my_project)$ git remote -v
origin firstname.lastname@example.org:/srv/git/my_project.git (fetch)
origin email@example.com:/srv/git/my_project.git (push)
This is a simple way of enabling other users to contribute to your projects and having a centralized repository where your main stuff goes.
Now every other user that wants to contribute should
server repo and keep that up to date.
A bash script based in this tutorial is available at https://github.com/marcanuy/centralize-git-repo.
- Code Review
- Creating a git server from a git repo
- Showing Untracked Files In Status After Creating New Directories In GitJanuary 2, 2016