Using Git fork branch in main repo

Some users may have a long-ago forked repo that the maintainer would like to track in the main repo as an orphan Git branch. That is, the maintainer does not want to merge the forked repo into the main repo, but would like to track the forked repo as a branch in the main repo.

The branch name “user-feat1” is arbitrary.

git switch --orphan user-feat1
# this allows unrelated history in the branch from the long-ago forked repo

git pull https://github.invalid/user/forked.git user-feat1
# copies the forked repo branch into the main repo branch "user-feat1"

git push -u origin user-feat1
# push the branch to the main repo

This can be useful for the maintainer to make changes to the user code that the user can put back in their repo without the maintainer needing to fork the user repo, which may not be possible on GitHub if the user forked from the maintainer’s repo originally.

The maintainer can get future changes from the user by doing:

git switch user-feat1

git pull https://github.invalid/user/forked.git user-feat1

git push