开发者

How do you update a bare repo from a remote source using git

开发者 https://www.devze.com 2023-03-08 05:18 出处:网络
I have a repo that is a bare clone of a github repo: git clone --bare git@github.com:PabloSerbo/maiden.git

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 k开发者_C百科now 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.


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号