Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
git-mirror
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
midgard
git-mirror
Commits
e15fa411
Commit
e15fa411
authored
Nov 06, 2019
by
midgard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
0 deletions
+116
-0
README.md
README.md
+41
-0
git-mirror.sh
git-mirror.sh
+75
-0
No files found.
README.md
0 → 100644
View file @
e15fa411
# Git mirror
Run this script to synchronize a repository once.
## Dependencies
*
bash
*
git
*
Tor and torify (see section "Tor")
## Usage
```
./git-mirror.sh <workdir> <leader> <follower...>
```
## Get started
Create a git repo, add remotes for the leader and the followers:
```
bash
mkdir
~/git-mirror-my-repo
;
cd
~/git-mirror-my-repo
git init
git remote add github https://github.com/interesting/repo
git remote add gitea ssh://git@git.example.org/me/interesting-repo
git remote add gitlab ssh://git@git.example.com/myself/interesting-repo
```
Make sure Tor is running (see section "Tor"). Then run the mirroring script:
```
bash
cd
git clone https://git.zeus.gent/midgard/git-mirror.git
;
cd
git-mirror
./git-mirror.sh ~/git-mirror-my-repo github gitea gitlab
```
The first remote, github is the leader. The others are followers that are updated.
## Tor
The leader is fetched over Tor through torify. Make sure Tor is running, or edit the script,
changing
`torify git fetch`
into
`git fetch`
.
## Motivation
GitHub has always been hypocritical, promoting open source while keeping its own stack closed. When
GitHub was bought by Microsoft, the author decided to stop using it. Unfortunately a lot of
software still only has a presence on GitHub. To make it easier to work with those, this simple
mirror script was written.
git-mirror.sh
0 → 100755
View file @
e15fa411
#!/bin/bash
set
-euo
pipefail
IFS
=
$'
\n
'
if
[[
$#
-lt
3
]]
;
then
echo
"Usage:
$0
<workdir> <leader> <follower...>"
exit
1
fi
cd
"
$1
"
leader
=
"
$2
"
shift
2
followers
=(
"
$@
"
)
echo
"Working directory:
$PWD
"
echo
"Leader remote:
$leader
"
echo
"Follower remotes:
${
followers
[*]
}
"
|
tr
'\n'
' '
echo
;
echo
torify git fetch
--prune
--multiple
"
$leader
"
git fetch
--prune
--multiple
"
${
followers
[@]
}
"
echo
echo
"Leader remote information:"
git remote show
-n
"
$leader
"
echo
echo
"Follower remotes information:"
git remote show
-n
"
${
followers
[@]
}
"
echo
branches
=(
$(
git show-ref |
sed
-n
's| refs/remotes/'
"
$leader
"
'/|\t|p'
)
)
echo
-e
"
${#
branches
[*]
}
branches at leader:"
echo
"
${
branches
[*]
}
"
IFS
=
$'
\t
'
errors
=(
)
error
()
{
echo
"XXX
$1
"
>
&2
errors[
${#
errors
[*]
}
]=
"
$1
"
}
for
branchspec
in
"
${
branches
[@]
}
"
;
do
set
$branchspec
leader_sha
=
"
$1
"
branch
=
"
$2
"
for
remote
in
"
${
followers
[@]
}
"
;
do
echo
echo
"Updating
$remote
/
$branch
"
# Prepare state to push
follower_ref
=
"refs/remotes/
$remote
/
$branch
"
if
!
git show-ref
--verify
--quiet
"
$follower_ref
"
;
then
echo
"Branch doesn't exist yet at remote, creating"
git reset
--hard
"
$leader_sha
"
--
else
echo
"Branch existed at remote, updating"
git reset
--hard
"
$follower_ref
"
--
git merge
--ff-only
"
$leader_sha
"
||
{
error
"
$remote
$branch
: FF not possible"
;
continue
;
}
fi
git push
"
$remote
"
"+HEAD:
$branch
"
||
{
error
"
$remote
$branch
: failed to push"
;
continue
;
}
done
done
if
[[
"
${#
errors
[*]
}
"
-ge
0
]]
;
then
echo
"Errors:"
echo
"
${
errors
[@]
}
"
else
echo
"No errors."
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment