[go: nahoru, domu]

Skip to content

๐Ÿ”ƒ A GitHub Action for syncing between two independent repositories using force push

Notifications You must be signed in to change notification settings

im-infomagnus/git-sync

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

40 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

This repo was forked from wei/git-sync to add git-lfs support by using a recent version of Alpine Linux.

Git Sync

A GitHub Action for syncing between two independent repositories using force push.

Features

  • Sync branches between two GitHub repositories
  • Sync branches to/from a remote repository
  • GitHub action can be triggered on a timer or on push (branches and tags)
  • Support for GIT LFS (PULL ALL from source then PUSH ALL to destination)

Quick Setup Step-by-Step

Please see the SSH Step-by-Step Guide for step-by-step instructions using SSH.

Usage

Always make a full backup of your repo (git clone --mirror) before using this action.

GitHub Actions

# .github/workflows/git-sync.yml

on:
  push:
    # Be sure to include all the relevant branching roots or this repo!
    branches:
      - main
      - release-*
    # Sync all tags, and generally limit tags to ONLY the branches being synced
    tags:
      - '*'

jobs:
  git-sync:
    runs-on: ubuntu-latest
    steps:
      - name: git-sync
        uses: valtech-sd/git-sync@v9
        with:
          source_repo: "git@github.com:source-org/source-repo.git"
          source_branch: "${{ github.event.ref }}"
          destination_repo: "git@github.com:destination-org/destination-repo.git"
          destination_branch: "${{ github.event.ref }}"
          source_ssh_private_key: ${{ secrets.SOURCE_SSH_PRIVATE_KEY }}
          destination_ssh_private_key: ${{ secrets.DESTINATION_SSH_PRIVATE_KEY }}
Using shorthand

You can use GitHub repo shorthand like username/repository.git.

Using ssh

The ssh_private_key, or source_ssh_private_key and destination_ssh_private_key must be supplied if using ssh clone urls.

source_repo: "git@github.com:username/repository.git"

or

source_repo: "git@gitlab.com:username/repository.git"
Using https

The ssh_private_key, source_ssh_private_key and destination_ssh_private_key can be omitted if using authenticated https urls.

source_repo: "https://username:personal_access_token@github.com/username/repository.git"

Set up deploy keys

You only need to set up deploy keys if the repository is private and the ssh clone url is used.

  • Either generate different SSH keys for both source and destination repositories or use the same one for both, leave the passphrase empty (note that GitHub deploy keys must be unique for each repository)
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • In GitHub, either:

    • Add the unique public keys (key_name.pub) to Repo Settings > Deploy keys for each repository respectively and allow write access for the destination repository

    or

    • add the single public key (key_name.pub) to Personal Settings > SSH keys
  • Add the private key(s) to Repo > Settings > Secrets for the repository containing the action (SSH_PRIVATE_KEY, or SOURCE_SSH_PRIVATE_KEY and DESTINATION_SSH_PRIVATE_KEY)

Advanced: Sync all branches

To Sync all branches from source to destination, use the wildcard branch filter on the push event of your action. But be careful, branches with the same name including master will be overwritten.

on:
  push:
    branches:
      - '*'

Advanced: Sync all tags

To Sync all tags from source to destination, use the wildcard tag filter on the push event of your action. But be careful, tags with the same name will be overwritten.

on:
  push:
    tags:
      - '*'

Docker

You can run this in Docker locally for testing and development.

$ docker run --rm -e "SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa)" $(docker build -q .) \
  $SOURCE_REPO $SOURCE_BRANCH $DESTINATION_REPO $DESTINATION_BRANCH

Author

Original Author: Wei He github@weispot.com

Fork Author: Valtech SD us.san_diego_engineering@valtech.com

License

MIT

About

๐Ÿ”ƒ A GitHub Action for syncing between two independent repositories using force push

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 88.0%
  • Dockerfile 12.0%