Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push from one bare git repo to another?

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?
like image 329
Saad Rehman Shah Avatar asked Nov 14 '12 05:11

Saad Rehman Shah


People also ask

Can I push from a bare repository?

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.

How do I push a git repository to another repository?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.

How do I clone a bare repository in git?

In order to clone your repository to create a new bare repository, you run the clone command with the --bare option. By convention, bare repository directory names end with the suffix . git , like so: $ git clone --bare my_project my_project.


2 Answers

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.

like image 172
Brian Campbell Avatar answered Sep 17 '22 01:09

Brian Campbell


Is there a way to push from one bare clone to the main github repo?

Yes, you don't have to be in a work tree to push changes from a bare repo.

Simply ssh to the place where you 'local master' is, and run:

git push origin master

As the other answer point out, you can also push directly from your local copy to a remote master, but it's sometimes more convenient to have an automated 'gatekeeper' repository like this that can be triggered to push changes out (eg. after review) to multiple remote repositories via automation, without worrying about setting up ssh keys and so forth for a specific individual to push the changes out.

like image 24
Doug Avatar answered Sep 19 '22 01:09

Doug