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...
You can use mirror repo feature: http://obahua.com/setup-your-private-git-hosting-with-gogs/#mirrorrepository .
Yes, but this mirrors from external to gogits, but i want from gogits to external...
I see... yeah, timing hook push to external address, it's possible but I need to do some tests before give you the answer.
Just curious, what's the case?
I want to push to one place and mirror for failover to guthub and bitbucket. =)
what if push failed to github when somehow commits are behind? how to deal with it?
Write somewhere error about it and stop to mirrors before user not fix this things.
maybe, sync is two operation, I think.
Definitely push only, user has to fix conflicts when fail to push
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.
ping, as i see gogs have email notify system, so we can use it to notify user about errors..
this related to #1623
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?
Wow. Thanks for sharing this post. So after reading that post I've managed to solve this via the post-receive
hook.
post-receive
hook in the project settings in gogs with the content of exec git push --mirror {EXTERNAL_REPO_URL}
;sudo git
to enter shell as user git
(or other user which your gogs is running as);hooks
directory, and execute the post-receive
hook using ./post-receive
;yes
. This only needs to be done once;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.
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..
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.
:trollface:
Any news?
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 :)
+1 for this feature
+1 for this feature please! Would be good to have my own Gogs hosted Git repo available on GitHub when needed.
+1
+1 for this feature. Also I want to sync to gitlab.com
+1
+1
two way mirror
+1
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.
Hmm, why isn't post-receive
enough?
Are you using Gogs as Git user?
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?
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
Thats's just my strategy to have repos synced, but it does no work from the browser, only with client git push
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)
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:
On your Gogs project page:
#!/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.
@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.
@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 ,
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.
Fyi, you can also use https and a token. On github, generate a token:
https://github.com/settings/tokens
Then the git hook becomes:
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.
Most helpful comment
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.