Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync to external repo #96

Closed
vtolstov opened this issue Apr 22, 2014 · 41 comments
Closed

sync to external repo #96

vtolstov opened this issue Apr 22, 2014 · 41 comments
Labels
🎯 feature Categorizes as related to a new feature

Comments

@vtolstov
Copy link

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...

@unknwon
Copy link
Member

unknwon commented Apr 22, 2014

You can use mirror repo feature: http://obahua.com/setup-your-private-git-hosting-with-gogs/#mirrorrepository .

@vtolstov
Copy link
Author

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

@unknwon
Copy link
Member

unknwon commented Apr 22, 2014

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
Copy link
Member

unknwon commented Apr 22, 2014

Just curious, what's the case?

@vtolstov
Copy link
Author

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

@unknwon
Copy link
Member

unknwon commented Apr 22, 2014

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

@vtolstov
Copy link
Author

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

@codeskyblue
Copy link
Contributor

maybe, sync is two operation, I think.

  1. git pull github
  2. git push && git push --tags

@unknwon
Copy link
Member

unknwon commented Apr 26, 2014

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

@unknwon unknwon self-assigned this May 2, 2014
@unknwon
Copy link
Member

unknwon commented May 6, 2014

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.

@vtolstov
Copy link
Author

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

@unknwon unknwon modified the milestones: 0.7.0, 0.7.5 Sep 3, 2015
@vtolstov
Copy link
Author

this related to #1623

@unknwon unknwon removed this from the 0.7.5 milestone Nov 15, 2015
@JokerQyou
Copy link

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?

@unknwon
Copy link
Member

unknwon commented Nov 21, 2015

@JokerQyou
Copy link

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.

@unknwon
Copy link
Member

unknwon commented Nov 21, 2015

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..

@JokerQyou
Copy link

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

@unknwon
Copy link
Member

unknwon commented Nov 21, 2015

:trollface:

@vtolstov
Copy link
Author

Any news?

@joepie91
Copy link

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 :)

@z2z
Copy link

z2z commented May 11, 2016

+1 for this feature

@binaryben
Copy link

binaryben commented May 26, 2016

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

@reinos
Copy link

reinos commented Sep 8, 2016

+1

@ericfont
Copy link

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

@danierukun
Copy link

+1

1 similar comment
@only1zf
Copy link

only1zf commented Oct 22, 2016

+1

@only1zf
Copy link

only1zf commented Oct 22, 2016

two way mirror

richmahn added a commit to richmahn/gogs that referenced this issue Nov 21, 2016
* Fixes gogs#87 - Make Hashtags Hyperlinks in HTML view

* Added hashtag_test.go for testing
richmahn added a commit to richmahn/gogs that referenced this issue Nov 23, 2016
* Fixes gogs#87 - Make Hashtags Hyperlinks in HTML view

* Added hashtag_test.go for testing
strk pushed a commit to strk/gogs that referenced this issue Nov 24, 2016
@adpande
Copy link

adpande commented Dec 3, 2016

+1

@JokerQyou
Copy link

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.

@unknwon
Copy link
Member

unknwon commented Feb 21, 2017

Hmm, why isn't post-receive enough?

@unknwon unknwon added the status: needs feedback Tell me more about it label Feb 21, 2017
@unknwon unknwon removed their assignment Feb 21, 2017
@unknwon unknwon removed the status: needs feedback Tell me more about it label Mar 10, 2017
@z2z
Copy link

z2z commented Apr 1, 2017

https://stackoverflow.com/questions/3284415/how-to-organize-and-setup-mirrored-backup-servers-for-git-repositories

@unknwon unknwon closed this as completed Apr 1, 2017
@dalareo
Copy link
Contributor

dalareo commented May 2, 2017

Are you using Gogs as Git user?

@GwynethLlewelyn
Copy link

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?

@thejmazz
Copy link

thejmazz commented Dec 5, 2017

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

@dalareo
Copy link
Contributor

dalareo commented Dec 5, 2017

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

@thejmazz
Copy link

thejmazz commented Dec 5, 2017

Hmm yeah, but it is known issue in #4338, so we just need to wait patiently :)

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

@LeOSW42
Copy link

LeOSW42 commented Dec 20, 2017

Here is a simple how-to for stupid people:

On your Gogs server:

root@server# sudo -i -u gogs
gogs@server$ ssh-keyscan github.com >> ~/.ssh/known_hosts # Necessary?
gogs@server$ ssh-keygen -b 4096 # Do not enter any password
gogs@server$ 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 git@github.com:dalu/forum.git

On any computer containing a clone, run:

me@my_pc$ git commit --allow-empty -m "test git hook"
me@my_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 git@github.com:dalu/forum.git
remote:    ebe061f..5d43139  master -> master
...

A stupid guy.

@xiay-lcw
Copy link

xiay-lcw commented Jan 6, 2018

@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.

@unknwon
Copy link
Member

unknwon commented Mar 6, 2018

@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.

@stealthybox
Copy link

@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.

@DanTulovsky
Copy link

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://TOKEN@github.com/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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🎯 feature Categorizes as related to a new feature
Projects
None yet
Development

No branches or pull requests