GithubHelp home page GithubHelp logo

lr7skquo / git-sync Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wei/git-sync

0.0 0.0 0.0 23 KB

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

Shell 87.48% Dockerfile 12.52%

git-sync's Introduction

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
  • To sync with current repository, please checkout Github Repo Sync

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
jobs:
  git-sync:
    runs-on: ubuntu-latest
    steps:
      - name: git-sync
        uses: wei/git-sync@v3
        with:
          source_repo: "source_org/repository"
          source_branch: "main"
          destination_repo: "destination_org/repository"
          destination_branch: "main"
          ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} # optional
          source_ssh_private_key: ${{ secrets.SOURCE_SSH_PRIVATE_KEY }} # optional, will override `SSH_PRIVATE_KEY`
          destination_ssh_private_key: ${{ secrets.DESTINATION_SSH_PRIVATE_KEY }} # optional, will override `SSH_PRIVATE_KEY`
Using shorthand

You can use GitHub repo shorthand like username/repository.

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: "[email protected]:username/repository.git"

or

source_repo: "[email protected]: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:[email protected]/username/repository.git"

Set up deploy keys

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

  • Either generate different ssh keys for both source and destination repositories or use the same one for both, leave passphrase empty (note that GitHub deploy keys must be unique for each repository)
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
  • 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 source_branch: "refs/remotes/source/*" and destination_branch: "refs/heads/*". But be careful, branches with the same name including master will be overwritten.

source_branch: "refs/remotes/source/*"
destination_branch: "refs/heads/*"

Advanced: Sync all tags

To Sync all tags from source to destination, use source_branch: "refs/tags/*" and destination_branch: "refs/tags/*". But be careful, tags with the same name will be overwritten.

source_branch: "refs/tags/*"
destination_branch: "refs/tags/*"

Docker

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

Author

Wei He [email protected]

License

MIT

git-sync's People

Contributors

wei avatar trivikr avatar rasodu avatar homerjam avatar shakti-garg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.