Git Repositories – How to Push from One Bare Repo to Another

gitgithubversion-control

Me and a couple of other guys from a big team are working on a separate page on the project. Let's call it groups page. While we work on the groups page, we need to exchange incomplete code, the code we wouldn't want to be sent to the central repo. And during this time, we also work on features not related to groups page, we do need to commit and push to the central server. I am looking at solutions for this problem, here are my ideas. Please comment on them.

We can't make a branch in the actual repo server because of the higher ups.

  1. Create and email diffs to each other, then lose changes and use the diff when we need to go back to groups page. The person getting the emails applies the diff. etc.
  2. We make a change to our code, commit it, but don't push it. Then whoever needs that incomplete code, can pull from us directly.
  3. Make another clone of the central server with –bare flag. So we can treat it as a local-central server just for the groups page. We can pull from it and create a separate workspace for groups page. We can push and pull to it.

Now each of these has problems.

  1. is too tedious. I wanna use git for it.
  2. When someone has pulled from me, and then worked on a new feature, and then he pushes (to the central server), then whatever he pulled from me doesn't get pushed to the server. How would he finally push it to the server when our groups page code is complete.
  3. The same problem. Is there a way I push from this local-central server to the main server? Both are bare repos of course. Is there a way to push from one bare clone to the main github repo?

Best Answer

3 is your best option. In fact, that's really how Git is intended to be used; with repositories for individual components, which feed into a more central repository when work is done.

There is no problem pushing someone else's changes. Lets say you make a change, and push it to the groups page repository. Then I pull that, make some changes, and push them back. Now we decide we're done. If I push to the central repository, that push will include both my changes, and your changes which my changes were based on.

You do not need to push from one bare repo to another. Git works by pushing from your local repo, to one or more remote repos. When you clone, there's a default remote repo called "origin". But you can have as many remote repos configured as you want. To set this up, let's say you have cloned from the central repo; that's called "origin". Now you create a bare repo: it's at ssh://some-machine.corp.com/path/to/groups-repo.git. In your local working repo, just do git remote add groups ssh://some-machine.corp.com/path/to/groups-repo.git, and you will have a reference to that groups repo. Now you can use git fetch, git pull, git push and so on with groups as well as with origin.

Related Question