From 7a0c1b54d0816ef76c29efe2f39efac293516ef8 Mon Sep 17 00:00:00 2001 From: programmerjake Date: Thu, 26 Mar 2020 01:54:12 +0000 Subject: [PATCH] git mirroring WIP --- resources/server-setup/git-mirroring.rst | 95 ++++++++++++++++-------- 1 file changed, 65 insertions(+), 30 deletions(-) diff --git a/resources/server-setup/git-mirroring.rst b/resources/server-setup/git-mirroring.rst index 26f4baa8c..78f646923 100644 --- a/resources/server-setup/git-mirroring.rst +++ b/resources/server-setup/git-mirroring.rst @@ -4,57 +4,92 @@ Git Mirroring to GitLab Steps for setting up automatic mirroring cron jobs: -* Add a new user: +#) Add a new user: - .. code:: bash + .. code:: bash - sudo adduser --disabled-login --system git-mirroring + sudo adduser --disabled-login --system git-mirroring -* Start a shell as the :code:`git-mirroring` user: +#) Start a shell as the :code:`git-mirroring` user: - .. code:: bash + .. code:: bash - sudo -H -u git-mirroring /bin/bash + sudo -H -u git-mirroring /bin/bash -* Switch to home directory: +#) Switch to home directory: - .. code:: bash + .. code:: bash - cd + cd -* Create an executable file :code:`sync.sh` (replace :code:`nano` with the editor of your choice): +#) Create an executable file :code:`sync.sh` (replace :code:`nano` with the editor of your choice): - .. code:: bash + .. code:: bash - touch sync.sh - chmod +x sync.sh - nano sync.sh + touch sync.sh + chmod +x sync.sh + nano sync.sh - * Type in the following contents: + a) Type in the following contents: - .. code:: bash + .. code:: bash - #!/bin/sh - for repo in ~/*.git; do - cd "$repo" && git fetch -q && git push -q gitlab || echo "sync failed for $repo" - done + #!/bin/sh + for repo in ~/*.git; do + cd "$repo" && git fetch -q && git push -q gitlab || echo "sync failed for $repo" + done - * Save and exit the editor. + #) Save and exit the editor. -* Create a ssh key: +#) Create a ssh key: - .. code:: bash + .. code:: bash - ssh-keygen + ssh-keygen - Press enter for all prompts -- leaving the file names as default and with an empty password. + Press enter for all prompts -- leaving the file names as default and with an empty password. -* For each repo to be mirrored: +#) For each repo to be mirrored: - * Create an empty repo using the GitLab website. + In the following commands, replace :code:`$UPSTREAM_URL` with the url for the upstream repo, :code:`$NAME` with the name selected for the local directory. - .. warning:: + a) Create an empty repo using the GitLab website. - Following these steps will overwrite anything that is in the GitLab repo. + .. warning:: - * Add the ssh key for the + Following these steps will overwrite anything that is in the GitLab repo. + + In the following commands, replace :code:`$MIRROR_URL` with the ssh url for the mirror, you can get it by clicking the Clone button for the empty repo you just created. + + b) Add the ssh key for the :code:`git-mirroring` user to the GitLab repo as a `deploy key with read/write access `_: + + Get the ssh public key for the :code:`git-mirroring` user: + + .. code:: bash + + cat ~/.ssh/id_rsa.pub + + #) Clone the upstream repo: + + .. code:: bash + + git clone --mirror "$UPSTREAM_URL" ~/"$NAME".git + + #) Switch to the directory where you just cloned the repo: + + .. code:: bash + + cd ~/"$NAME".git + + #) Add the mirror as a new remote to allow pushing to it: + + .. code:: bash + + git remote add --mirror=push gitlab "$MIRROR_URL" + + #) Try pushing to the new remote to ensure everything is operating correctly: + + .. code:: bash + + git push gitlab + -- 2.30.2