How do I merge commits from a forked repo to a private repo?

Viewed 44

I have a forked repo and a private repo. The private repo is for a side project based off the forked repo. I'm working on a different branch from master in the private repo (ie new-changes). I want to be able to occasionaly fetch new updates and add those commits from the forked repo to my private repo on a branch other than master (i.e. fetch-update) and then merge the two branches into dev for testing before merging it into master. What's the best way about doing this?

fork -> private/dev/fetch-update -> private/dev

private/dev/new-changes -> /private/dev

EDIT:

Okay, I figured most of the steps out doing push --mirror from the fork to the private repo. But I want to push --mirror into private/dev/fetch-update from fork/master

1 Answers

Let's say we have git://forked-repo-url and git://private-repo-url, then

# clone the private repo
git clone git://private-repo-url
# change dir into the private repo
cd private-repo
# add the forked repo as an another remote
git remote add forked git://forked-repo-url
# fetch the newly created forked repo remote 
git fetch forked
# switch to a new branch `dev` in the local copy 
git switch -c dev
# merge changes from the `main` branch of the forked repo into the local `dev` branch
git merge forked/main
# or better then merging rebase on it
git rebase forked/main
Related