Gogs: sync to external repo

45

Is that possible to create ability to do external sync from gogits for example to giithub and bitbucker and other services?
I thinks that no need much work...

vtolstov picture vtolstov  路  22 Apr 2014

Most helpful comment

14

Guys, if you just want to vote for this feature, you might want to add your reaction to the first comment of this issue. You can react with 馃憤 and many other emojis.
But please stop commenting with meaningless content like "+1". Commenting with those content would not contribute to the implementation, and they're really annoying for those who want to keep an eye on this issue. Every time you add a comment like "+1", all the commented and subscribed users receive an email.

JokerQyou picture JokerQyou  路  3 Dec 2016

All comments

-10
unknwon picture unknwon  路  22 Apr 2014
0

Yes, but this mirrors from external to gogits, but i want from gogits to external...

vtolstov picture vtolstov  路  22 Apr 2014
0

I see... yeah, timing hook push to external address, it's possible but I need to do some tests before give you the answer.

unknwon picture unknwon  路  22 Apr 2014
0

Just curious, what's the case?

unknwon picture unknwon  路  22 Apr 2014
7

I want to push to one place and mirror for failover to guthub and bitbucket. =)

vtolstov picture vtolstov  路  22 Apr 2014
0

what if push failed to github when somehow commits are behind? how to deal with it?

unknwon picture unknwon  路  22 Apr 2014
0

Write somewhere error about it and stop to mirrors before user not fix this things.

vtolstov picture vtolstov  路  22 Apr 2014
0

maybe, sync is two operation, I think.

  1. git pull github
  2. git push && git push --tags
codeskyblue picture codeskyblue  路  26 Apr 2014
0

Definitely push only, user has to fix conflicts when fail to push

unknwon picture unknwon  路  26 Apr 2014
0

Webhook has been done, but users need to receive message when fail to sync external. So this feature still need delay for implementing message system.

unknwon picture unknwon  路  6 May 2014
0

ping, as i see gogs have email notify system, so we can use it to notify user about errors..

vtolstov picture vtolstov  路  20 May 2015
0

this related to #1623

vtolstov picture vtolstov  路  11 Sep 2015
0

After reading some blog posts of mirroring external git repos to github, I think this is possible. Sadly, I did not get it to work.

About GitHub mirrors told us that we can use post-receive hook to push commits to github, after these commits were received by gogs; And Duplicating a repository told us how to manually push to a mirror, as well as Setting up backup (mirror) repositories on GitHub.

However, what blocked me from achieving this is that gogs seem not to store its repos as ordinary git repos. Now, when I say 'ordinary git repos', I mean we can see its status via git status inside that folder. Gogs seems to store all these git information as structured folders. So doing something like git push --mirror github does not work in post-receive scripts.

I wonder how gogs manipulates git operations without storing the repo in the ordinary form. @Unknwon do you have any example of how to write a post-receive ( or any other git hooks ) script that works in gogs?

JokerQyou picture JokerQyou  路  21 Nov 2015
0
unknwon picture unknwon  路  21 Nov 2015
0

Wow. Thanks for sharing this post. So after reading that post I've managed to solve this via the post-receive hook.

  • First set a post-receive hook in the project settings in gogs with the content of exec git push --mirror {EXTERNAL_REPO_URL};
  • then, instead of directly pushing to this gogs project, use sudo git to enter shell as user git (or other user which your gogs is running as);
  • thirdly, enter the folder where all your gogs repos are stored, and locate the target project;
  • enter the hooks directory, and execute the post-receive hook using ./post-receive;
  • when prompted with host key verification, enter yes. This only needs to be done once;
  • exit git user.

From now on, all gogs repo on the same server should be able to be mirrored to external git services like github, by using the post-receive hook.
The key here is that you have to confirm the host key of external git server during the first push.

JokerQyou picture JokerQyou  路  21 Nov 2015
0

The key here is that you have to confirm the host key of external git server during the first push.

You can achieve that by manually push once..

unknwon picture unknwon  路  21 Nov 2015
0

Yes, but not much people would do it as git user. :laughing:
Or you can just add the host key to ~/.ssh/known_hosts of git user.

JokerQyou picture JokerQyou  路  21 Nov 2015
0

:trollface:

unknwon picture unknwon  路  21 Nov 2015
0

Any news?

vtolstov picture vtolstov  路  11 Mar 2016
0

The key here is that you have to confirm the host key of external git server during the first push.

This can be sidestepped by changing StrictHostKeyChecking. While that answer is for using SSH manually, you can also set SSH options for Git.

I'd also be very happy to see this implemented :)

joepie91 picture joepie91  路  28 Mar 2016
0

+1 for this feature

z2z picture z2z  路  11 May 2016
0

+1 for this feature please! Would be good to have my own Gogs hosted Git repo available on GitHub when needed.

BinaryBen picture BinaryBen  路  26 May 2016
0

+1

reinos picture reinos  路  8 Sep 2016
0

+1 for this feature. Also I want to sync to gitlab.com

ericfont picture ericfont  路  19 Sep 2016
0

+1

danierukun picture danierukun  路  15 Oct 2016
0

+1

onlyzf picture onlyzf  路  22 Oct 2016
2

two way mirror

onlyzf picture onlyzf  路  22 Oct 2016
0

+1

adpande picture adpande  路  3 Dec 2016
14

Guys, if you just want to vote for this feature, you might want to add your reaction to the first comment of this issue. You can react with 馃憤 and many other emojis.
But please stop commenting with meaningless content like "+1". Commenting with those content would not contribute to the implementation, and they're really annoying for those who want to keep an eye on this issue. Every time you add a comment like "+1", all the commented and subscribed users receive an email.

JokerQyou picture JokerQyou  路  3 Dec 2016
2

Hmm, why isn't post-receive enough?

unknwon picture unknwon  路  21 Feb 2017
0

Are you using Gogs as Git user?

dalareo picture dalareo  路  2 May 2017
0

I just wanted to mention that the checklist provided by @dalu works so flawlessly that it ought to be part of the official gogs documentation! Is there any way we can alert the documentation maintainers?

GwynethLlewelyn picture GwynethLlewelyn  路  15 Sep 2017
4

You can also use a personal access token with repo access, and then your post-receive hook like so:

#!/bin/bash
git push --mirror https://<token>@github.com/<user>/<repo>.git
thejmazz picture thejmazz  路  5 Dec 2017
0

Thats's just my strategy to have repos synced, but it does no work from the browser, only with client git push

dalareo picture dalareo  路  5 Dec 2017
1

Hmm yeah, but it is known issue in https://github.com/gogits/gogs/issues/4338, so we just need to wait patiently :)

FWIW, it works in gitea (commits from UI, as well as making branches on UI)

thejmazz picture thejmazz  路  5 Dec 2017
4

Here is a simple how-to for stupid people:

On your Gogs server:

[email protected]# sudo -i -u gogs
[email protected]$ ssh-keyscan github.com >> ~/.ssh/known_hosts # Necessary?
[email protected]$ ssh-keygen -b 4096 # Do not enter any password
[email protected]$ cat /home/gogs/.ssh.id_rsa.pub # Copy following line

On your Github account:

  • Add a new SSH key by pasting clipboard content
  • Create a new empty repository and copy the ssh clone URL

On your Gogs project page:

  • In settings > hooks > post-receive: (replace URL by the previously pasted one)
#!/bin/bash
git push --mirror [email protected]:dalu/forum.git

On any computer containing a clone, run:

[email protected]_pc$ git commit --allow-empty -m "test git hook"
[email protected]_pc$ git push
...
remote: Warning: Permanently added the RSA host key for IP address '192.30.253.112' to the list of known hosts.
remote: To [email protected]:dalu/forum.git
remote:    ebe061f..5d43139  master -> master
...

A stupid guy.

LeOSW42 picture LeOSW42  路  20 Dec 2017
0

@Unknwon Just want to point out that all 3 hooks currently exposed through front-end are server side hooks. None of them are invoked when a merge happens through pull request.

xiay-lcw picture xiay-lcw  路  6 Jan 2018
0

@xiayhub hmm... ? The known problem is custom hooks are not called when use web editor, not default ones. You may need to file a formal issue report with more details.

unknwon picture unknwon  路  6 Mar 2018
0

@Unknwon ,
What @xiayhub is saying is that post-receive doesn't run when you merge a pull request.
If you're using post-receive to sync to GitHub, it won't sync when you merge PR's.

I tried getting around this by manually installing post-commit and post-merge into the repo, but that didn't seem to work either.

I'll open an issue.

stealthybox picture stealthybox  路  23 Mar 2018
1

Fyi, you can also use https and a token. On github, generate a token:

https://github.com/settings/tokens

Then the git hook becomes:

!/bin/bash

git push --mirror https://[email protected]/USER/REPO.git

This way you don't need to mess with ssh keys. Of course, anyone who can see the git hooks in gogs, can see the token.. so be careful.

DanTulovsky picture DanTulovsky  路  17 Feb 2019