[HOWTO] Keeping your fork up-to-date

There is another option. Keep a private fork for a public repository if you want to add new “secret” functionality or some credentials.

Summary
Do a bare clone of the public repo.
Create a new private one.
Do a mirror push to the new private one.
Steps:

  1. Create a new empty private repository via Github.
    
  2. Clone the public repository that we want to base our private repository on:

    ```
    git clone --bare https://github.com/foo/public-repository.git
    ```
    
  3. Move into the cloned repository and execute a push with the --mirror flag:

    cd public-repository
    git push --mirror https://github.com/foo/private-repository.git
    

    The --mirror flag push ensures that all the branches and tags that are available in the public repository are replicated in the new location.

  4. The public repository that we cloned in step 2 can now be deleted:

    cd ..
    rm -rf public-repository
    
  5. In order to work on the private repository, we just need to clone it:

    $ git clone https://github.com/foo/private-repository.git
    $ cd private-repository
    
1 Like