[HOWTO] Keeping your fork up-to-date

Git makes it super easy to keep your own fork up-to-date with it’s upstream source.

DO NOT keep downloading files you think have changed and copying them over manually, this is both cumbersome, unnecessary, and error-prone.

Option 1: GitHub (Fork to a public Repo)

NB: Unfortunately there’s no way to fork to a private repo in GitHub. This meas you should either use banana’s build-args from the dashboard for your API keys, or choose a different method below.

  1. Fork the repo

and then

(Uncheck “Copy the main branch only” if you want access to other branches too).

  1. To keep it up-to-date, go to YOUR FORK’s page on github:

You can compare the changes (if you want) or simply click Update branch, and with just that one click, you get:

You can now git pull locally to pull in the merged changes from (your) github repo.

Option 2: Command line

# Do this once to add the upstream repo as a "remote"
$ git remote add upstream git@github.com:kiri-art/docker-diffusers-api.git

# Fetch upstream's latest updates (of all branches)
$ git fetch upstream

# Merge the updated code into your fork
$ git merge upstream/main # or upstream/dev, etc.

Option 3: Bare Clone / Mirror Push

See this post below, with big thanks to @Klaudioz.

Notes

Please ask below if anything is not clear, or if you have suggestions to improve this for others.

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

Oh, great, thanks! Never worked that way before, thanks for sharing and for the detailed step-by-step! Adding a link to this post as Option 3, and will add a note for Option 1 that it can’t be used to make a private repo (thanks for the reminder).