5

I have a repo that is a bare clone of a github repo:

 git clone --bare git@github.com:PabloSerbo/maiden.git

A number of developers clone that repo and push back to it.

Another developer has committed directly to the github repo.

I would like to know how to get the changes on github back into the bare repo for the other developers to pull from.

I have tried:

 git fetch origin

Which seems to fetch to:

 remotes/origin/master

But I can't get local head to have the changes.

The closest question I can find is this:

How do I update my bare repo?

This suggests mirroring, but I would like to know if there is a way to achieve this without the need to mirror.

Community
  • 1
  • 1
serby
  • 4,186
  • 2
  • 24
  • 25
  • I'm confused -- your bare clone has an origin set? Most bare repos (even clones) don't as they _are_ origin. – ebneter May 26 '11 at 01:00
  • Why are your devs pushing to two different repos? In that sort of workflow you usually want to agree on which repo will be the "common" one everyone pushes to, probably the github one in this case. – Tekkub May 27 '11 at 19:41

3 Answers3

4

clone the bare repo yourself. This will have origin pointing to that. Now add the github repo as 'github' remote. You can now fetch the branches and tags from github and in turn push them to origin.

git fetch github
git push origin github/yourbranchname:yourbranchname

Hope this helps.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • Although your suggestion doesn't answer my question. I do agree this is a better workflow to keep 2 remote repos in sync. I would still like to know if what I'm asking is possible without the need of a separate repo with a working copy. – serby May 25 '11 at 23:49
  • 1
    @PabloSerbo I don't think it's possible without a working copy — you have to merge, and if there are conflicts, how will you resolve them with no working copy? – ebneter May 26 '11 at 01:06
  • @ebneter That was the bit of logic I couldn't quite get my head round last. Makes perfect sense in cold light of day. Thanks to both of you for your help. – serby May 26 '11 at 08:40
3

This approach works for me:

git fetch origin master:master

and then

git update-server-info (I am using http to access bare repository, not sure that it has sense if you use another type ot transport  )

But it updates only master branch. And I still don't know how to update all branches

ilyabasiuk
  • 4,270
  • 4
  • 22
  • 35
0

I found out that it's also necessary to perform a git remote update to the bare / mirror repo. Otherwise HEAD and master are behind. It is usually important to move HEAD ahead after verifying whether the fetched commits are ok or not.

marcgc@deb6marc:~/projs/8568/svn/mix3/mIST_SE.git$ git fetch geekisp
carnicer@login.geekisp.com's password: 
remote: Counting objects: 19, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 14 (delta 10), reused 0 (delta 0)
Unpacking objects: 100% (14/14), done.
From login.geekisp.com:marc/tecsidel/git/mix/mIST_SE
 * [new branch]      master     -> geekisp/master
marcgc@deb6marc:~/projs/8568/svn/mix3/mIST_SE.git$ git lol
* 835bede (geekisp/master) dont crash
* 6de0db7 v2.0.11
* 42336a0 rename PicSearchAlga to PicSearch
* 845728d goto with 2 pix instead of 3
* a08ca13 (HEAD, master) v2.0.10
* 51c984e v2.0.8 : show CC in report (bugfix)

Here HEAD and master are pointing to the same commit before performing the fetch. In order to make them point to the latest commit, it is necessary to do a remote update:

marcgc@deb6marc:~/projs/8568/svn/mix3/mIST_SE.git$ git remote update geekisp
Fetching geekisp
carnicer@login.geekisp.com's password: 
marcgc@deb6marc:~/projs/8568/svn/mix3/mIST_SE.git$ git lol
* 835bede (HEAD, geekisp/master, master) dont crash
* 6de0db7 v2.0.11

Now all refs (HEAD, master) are pointing to the latest commit.

EDIT / upgrade :

After happily writing my answer, I found out that my solution did not work anymore. I tried to the same on another computer.

marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$ git fetch geekisp
carnicer@login.geekisp.com's password:
Fetching geekisp
remote: Counting objects: 20, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 14 (delta 11), reused 0 (delta 0)
Unpacking objects: 100% (14/14), done.
From login.geekisp.com:marc/tecsidel/git/mix/mIST_SE
   835bede..4e2e92e  master     -> geekisp/master
marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$ 
marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$ git lol
* 4e2e92e (geekisp/master, geekisp/HEAD) best search type, finds something
* d16406a start to see search types for sweden
* 9809ccd v2.0.12
* 835bede dont crash
* 6de0db7 v2.0.11
* 42336a0 rename PicSearchAlga to PicSearch
* 845728d goto with 2 pix instead of 3
* a08ca13 (HEAD, master) v2.0.10
marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$ 
marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$ git remote update geekisp
carnicer@login.geekisp.com's password:
Fetching geekisp
marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$ 

I was getting stuck here. The HEAD and master were not pointing at the latest commit as expected.

marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$ git lol
* 4e2e92e (geekisp/master, geekisp/HEAD) best search type, finds something
* d16406a start to see search types for sweden
* 9809ccd v2.0.12
* 835bede dont crash
* 6de0db7 v2.0.11
* 42336a0 rename PicSearchAlga to PicSearch
* 845728d goto with 2 pix instead of 3
* a08ca13 (HEAD, master) v2.0.10

It looks like my solution did not work. After googling I found a solution.

It seems the fetch command also needs to have a refspec, like master:master in my case.

marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$ git fetch geekisp master:master
carnicer@login.geekisp.com's password:
From login.geekisp.com:marc/tecsidel/git/mix/mIST_SE
   a08ca13..4e2e92e  master     -> master
marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$
marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$ git lol
* 4e2e92e (HEAD, geekisp/master, geekisp/HEAD, master) best search type, finds somet
* d16406a start to see search types for sweden
* 9809ccd v2.0.12
* 835bede dont crash
* 6de0db7 v2.0.11
* 42336a0 rename PicSearchAlga to PicSearch
* 845728d goto with 2 pix instead of 3
* a08ca13 v2.0.10
* 51c984e v2.0.8 : show CC in report (bugfix)
marc@ibm:~/tecsidel/git/mix2/mIST_SE.git$

So that seems to be it.

carnicer
  • 494
  • 3
  • 9