Push from action to different remote repo


I am trying to set this up for a while but I am now completely clueless on how to do this.

What I have and what am trying to do:

  • I have a repo at github where 2 (or more) developers will push the changes.

  • I have a server setup on DigitalOcean that has bare git repo 

  • On the digital ocean bare repo I have a post-recieve hook that performs checkout and places the code in a place from where it gets served (through a server)

  • From my local machine I am able to push the changes to the Digital Ocean (through SSH)

  • Currently after any changes are merged in master, I pull the changes from github and manually push them to Digital Ocean remote 

  • This is what I want to automate through github actions. 

  • So when any change is merged in master, I want the action to perform a push to my server’s remote repo. 

Is this possible using actions ? If yes, where do I even begin ? where and how would I add the ssh keys - provided that DO has a somewhat complicated method to add new keys - so I would like the setup to be done only one time.

the more I think about it, it looks like I am missing some point here. Is it possible to do a different setup for what I want to achive? 



@sambhav-gore  It is possible to push to another repo during workflow run via ssh, there is an action to install SSH key: https://github.com/shimataro/ssh-key-action

You need to store SSH_PRIVATE_KEY and KNOWN_HOSTS into secrets. 

I don’t have Digital Ocean , I use bitbucket to instead.  Please see my workflow yml, it could push the master branch of my github repo to a bitbuket repo . Please note that if you use checkout@v2, you need to set fetch-depth : ‘0’ to get all history of master branch. 

name: push to bitbucket
on: push
    runs-on: ubuntu-latest
    - uses: actions/checkout@v2
        fetch-depth: '0'
        ref: 'master'
    - name: Install SSH key
      uses: shimataro/ssh-key-action@v2
         key: ${{ secrets.SSH_PRIVATE_KEY }}
         name: id_rsa # optional
         known_hosts: ${{ secrets.KNOWN_HOSTS }}
    - run: |
        git remote add bitbucket git@bitbucket.org:jingzhuyan/new1.git
        git config --global user.email " ****@***"
        git config --global user.name "yanjingzhu"
        git checkout master
        git push -u bitbucket master

I’m trying something similar - see workflow file and this run, where I fail with git@bitbucket.org: Permission denied (publickey). i’m 100% sure that the private key I’ve added as a repository secret matches the public key I’ve set at bitbucket.

What am I doing wrong?