Reputation: 11
in GitLab if branch merge into master then I want to push automatically to GitHub how it is possible
Upvotes: 2
Views: 777
Reputation: 131
Gitlab has an automated way of providing this. In your Gitlab repository, go to Settings->Repository->Mirroring repositories.
Enter the Github repository with your username included. i.e. https://[email protected]/group/project.git
Set the Mirror direction to Push.
Use a GitHub personal access token as your password.
Upvotes: 1
Reputation: 1329082
At the server level (meaning on gitlab.com side), you would need to register a webhook or use a GitLab integration in order to cal an external listener/service to do the push to GitHub on each GitLab push event.
Or, similarly to GitHub Actions, you can execute commands directly on GitLab server through a GitLab-CI pipeline.
But making a GitLab pipeline work with other services might not be trivial (see issue 3835)
So the other approach is on the client side (easier to do, but harder to deploy to each client, since it is no longer centralized on the server side)
You can simply configure your local Git repository setting to push to both GitLab and GitHub in one git push
command.
git remote set-url --add --push origin [email protected]:<user>/my-project.git
git remote set-url --add --push origin [email protected]:<user>/my-project.git
But that would apply to any push, not just master (and not just on merge)
For just master, you can define a new remote:
git remote add all
git remote set-url --add --push all [email protected]:<user>/my-project.git
git remote set-url --add --push all [email protected]:<user>/my-project.git
git branch --set-upstream-to=all master
That way, only master
will push by default to both GitLab and GitHub.
Or, still locally, you can define a post-merge hook, as suggested by Polygnome in the comments:
It will:
That only works if the local user is doing the merge though.
Upvotes: 0