0

I want to install an intermidiary git repository and all my team members can make a commit and push in this repository.

When all team memebers finish all tasks, all committed changes in intermidiary repository must be delivered in the offcial git repository located in another server hosted in the internet.

My question, is it possible to do this configuration? and how to do it?

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
developer
  • 4,744
  • 7
  • 40
  • 55

5 Answers5

2

It is possible.

You can setup a git server in one of your LAN computer by following the tutorial here or using tools like Gitolite. Once you have the local git repo ready, you can grant access to your team members.

To sync your local server to the central server, setup one local copy with two remotes. Then you can simply git pull from local server to get the local changes and git push to the central server. You can schedule this task by using a passphrase-less key-pair to access both servers.

More details on setting up multiple git remotes is available here

Community
  • 1
  • 1
gnuanu
  • 2,252
  • 3
  • 29
  • 42
2

Yes you can, because as GIT is a Distributed Revision Control System. Any cloned repository might be used as an origin (destination) of other repositories.

Let's say you want to make a proxy repository for a "main" repository called main.git

git clone --bare path_to_main_repo/main.git path_to_proxy_repo/proxy.git
git clone path_to_proxy_repo/proxy.git path_to_working_repository/working_repository 

You can then push from your working_repository to the proxy and from the proxy to your main repository.

Keep in mind that when using GIT, any given repository may play the role of a mainTargeted / proxy / orAnythingElse repository.

Ahmed Siouani
  • 13,701
  • 12
  • 61
  • 72
1

If I understand you correctly, you would like to put initial changes to git repos A

Once some point is reached ( a milestone, a date etc ) all the changes to repos A are taken and applied to repos B

Most development teams do this with a single repos and branching

However, it's possible to have branches wherever you like.

There is an example in the man page for the git remote command

EXAMPLES
   ·   Add a new remote, fetch, and check out a branch from it

           $ git remote
           origin
           $ git branch -r
           origin/master
           $ git remote add linux-nfs git://linux-nfs.org/pub/linux/nfs-2.6.git
           $ git remote
           linux-nfs
           origin
           $ git fetch
           * refs/remotes/linux-nfs/master: storing branch 'master' ...
             commit: bf81b46
           $ git branch -r
           origin/master
           linux-nfs/master
           $ git checkout -b nfs linux-nfs/master

Your repos A could be like the linux-nfs in the above example. After doing this, git merge could be used to combine the two

Vorsprung
  • 32,923
  • 5
  • 39
  • 63
1

Try using bare repository (http://git-scm.com/book/ch4-2.html)

Basically, you intiate a new git bare repo like

git init --bare

Add this repository to the remote for each of your developer using

git add remote upstream_intermediate_bare path/to/bare/repo

And then push your commit to the upstream bare repository using

git push upstream_intermediate_bare branch_name

Next, in your official git repo, add another remote

git add remote downstream_intermediate_bare path/to/bare/repo
git pull downstream_intermediate_bare branch_name

Bare repositories are important for the common case of a remote repository used only as a push and pull source. Check this.

Edit: Sample example

cd ~/Desktop/test
mkdir dev1
mkdir official
cd dev1 && git init && touch file && git add . && git commit -m "msg" && cd ..
cd official && git init && cd ..
git init --bare interim
cd dev1 && git remote add upstream_intermediate_bare ../interim && cd ..
cd official && git remote add downstream_intermediate_bare ../interim && cd ..
cd dev1 && git push upstream_intermediate_bare master && cd ..
cd official && git pull downstream_intermediate_bare master && cd ..

So with the above example, the developer code is in directory dev1, he pushes to a bare repository inside within which you can't do a pull or a push, you have to add add it in your remotes and operate upon it, and the official repo just pulls from the bare repository.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • when I try this `git add remote upstream_intermediate_bare ~/Desktop/git_local` I get this the folowing error: `fatal: This operation must be run in a work tree` – developer Oct 02 '13 at 09:59
  • for my case the official git is already existing in a remote server and not present in my LAN – developer Oct 03 '13 at 16:16
  • How can I apply your example in my case? – developer Oct 03 '13 at 16:16
  • @AhmedZRIBI I misinterpreted `offcial git repository located in another server hosted in the internet` to be a production checked out repo. It now seems plausible, that that official repo might be a github/bitbucket repo, in which case it would be a bare repo by itself, and hence my solution will fail – Anshul Goyal Oct 03 '13 at 16:51
1

Suppose to work in a project. You just pull code from master, and open new branch:

git pull origin master
git checkout -b new-branch
...

Now you can push your branch or just start to work in it before push some commit.

...
git add .
git commit -am 'I am pushing in bew-branch'
...
git add .
git commit -am 'I am pushing in bew-branch'
...

You have some feature in your branch (no in master) You are the first developer that has worker in this branch so, ... you can push it in origin.

...
git push origin new-branch
...

Now exists a branch called 'origin/new-branch' and all developers can pull from this branch. Now you continue to commit in your locasl branch:

...
git add .
git commit -am 'I am pushing in bew-branch'
...
git add .
git commit -am 'I am pushing in bew-branch'
...

Other developer pushed some code and now you need to pull

...
git pull origin master
...
    Fix merge
...
git push origin new-branch
...

And finally you can put all commit in master

...
git checkout master
git merge new-branch
git push origin master

The end.

sensorario
  • 20,262
  • 30
  • 97
  • 159