Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Gitlab2GithubMirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hispanico
Gitlab2GithubMirror
Commits
3ad3661f
Commit
3ad3661f
authored
7 years ago
by
Hispanico
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Gitlab2GithubMirror.sh
+79
-0
79 additions, 0 deletions
Gitlab2GithubMirror.sh
README.md
+41
-0
41 additions, 0 deletions
README.md
with
120 additions
and
0 deletions
Gitlab2GithubMirror.sh
0 → 100644
+
79
−
0
View file @
3ad3661f
#!/bin/bash
#
# Shell script to config a Gitlab project to automatically mirror on Github.
# -------------------------------------------------------------------------
# File Name: Gitlab2GithubMirror.sh
# Version: 1.0
# Last updated: Aug 2017
# -------------------------------------------------------------------------
# Released under the GPLv3 Licence
#
# @AUTHORS: Hispanico (hispanico@ninux.org)
# -------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# DEFINITION VARIABLES
# ---------------------------------------------------------------------------
GitlabNamespace
=
$1
GitlabProjectName
=
$2
GithubUser
=
$3
sys_gituser
=
"git"
sys_gitgroup
=
"git"
GitLabReposPath
=
"/var/opt/gitlab/git-data/repositories"
GitLabProjectPath
=
"
$GitLabReposPath
/
$GitlabNamespace
/
$GitlabProjectName
.git"
#==========================================================================
if
[
$#
-ne
3
]
;
then
echo
""
echo
"Usage: "
echo
" sh
$0
<GitlabNamespace> <GitlabProjectName> <GithubUser>"
echo
""
echo
"Arguments:"
echo
" GitlabNamespace: Namespace on Gitlab Server"
echo
" GitlabProjectName: Project name Gitlab Server"
echo
" GithubUser: Github username"
echo
""
echo
"Examples:"
echo
" sh
$0
MyNameSpace MyProject MyGithubUser"
echo
""
exit
1
fi
# ---------------------------------------------------------------------------
# Check if the Gitlab Project exist
# ---------------------------------------------------------------------------
if
[
!
-d
$GitLabProjectPath
]
;
then
echo
"Error: Project doesn't exist on Gitlab Server"
exit
1
fi
# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
# Add github remote to git config
if
[
$(
grep
"git@github.com:
$GithubUser
/
$GitlabProjectName
.git"
$GitLabProjectPath
/config 2>&1
>
/dev/null
)
]
;
then
cat
<<
EOF
>>
$GitLabProjectPath
/config
[remote "github"]
url = git@github.com:
$GithubUser
/
$GitlabProjectName
.git
fetch = +refs/heads/*:refs/remotes/github/*
EOF
fi
#Create custom hooks to github mirroring
[
!
-d
$GitLabProjectPath
/custom_hooks
]
&&
mkdir
$GitLabProjectPath
/custom_hooks
||
:
cat
<<
EOF
>
$GitLabProjectPath
/custom_hooks/post-receive
#!/usr/bin/env bash
git push --mirror github
EOF
chmod
+x
$GitLabProjectPath
/custom_hooks/post-receive
chown
-R
$sys_gituser
:
$sys_gitgroup
$GitLabProjectPath
/custom_hooks/
echo
"The Project
$GitlabProjectName
has been configured"
This diff is collapsed.
Click to expand it.
README.md
0 → 100644
+
41
−
0
View file @
3ad3661f
# How to automatically mirror a Gitlab project to Github
Sometimes you need to auto-sync Gitlab repos to Github, so here's what you have to do.
We need to add a post-receive hook in Gitlab's repo, on the Gitlab's server, which will trigger every time you do a push to the Gitlab's repo.
To add the post-receive hook, you must follow the steps:
1.
Create the ssh-key for git user on the Gitlab server:
```
su git
bash
ssh-keygen
cat ~/.ssh/id_rsa.pub
```
2.
Add this pub key to Github with write access: https://github.com/Organization/RepoName/settings/keys
3.
Check the connection to GitHub on the Gitlab server:
```
su git
ssh -T git@github.com
```
4.
Run Gitlab2GithubMirror.sh script on the Gitlab server to configure your project.
## Details
```
Usage:
sh Gitlab2GithubMirror.sh <GitlabNamespace> <GitlabProjectName> <GithubUser>
Arguments:
GitlabNamespace: Namespace on Gitlab Server
GitlabProjectName: Project name Gitlab Server
GithubUser: Github username
Examples:
sh Gitlab2GithubMirror.sh MyNameSpace MyProject MyGithubUser
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment