Git maintainer feature branch workflow

Major Git projects commonly have a workflow where other contributors fork a primary Git repository, make changes, and then contribute back to the primary project. This article describe the maintainer workflow. The contributor workflow is in a separate article.

This workflow is also suitable for projects using Git submodules, where you may want a submodule to temporarily use a branch from another repository.

Maintainers of a primary Git repo can make a local copy of the forked Git branch from the contributor’s Git repo to ensure the changes work as desired. Two ways for the maintainer to make this local copy are described in this article.

add remote upstream

This workflow is suited to accommodate regular contributors to a project, for example colleagues or employees. In this example, we assume the primary project branch to merge new contributions into is “main” and that the remote contributor branch is “add-feat1”.

git remote add coworker-42 https://github.invalid/coworker-42/forked_project.git

git fetch coworker-42

git switch coworker-42/add-feat1

Ensure that things work as desired. To merge the changes, do like:

git merge --no-ff add-feat1

Check the Git history to verify the desired commits.

git log

Push to the primary project as desired.

temporary local branch

This workflow is suitable for occasional contributors. It avoids cluttering the local repo with many upstream repos metadata in .git/config.

On the local copy of the primary project, create a temporary branch in which to put the contributor’s remote branch. Here we assume the remote branch is “add-feat1”:

git switch -c contrib-add-feat1

git pull https://github.invalid/contrib/forked_project.git add-feat1

After testing the new code to see that it’s suitable, merge the changes into the primary project:

git switch main

git merge --no-ff contrib-add-feat1

Check the Git history to verify the desired commits.

git log

Push to the primary project as desired. Finally, delete the temporary local branch:

git branch -d contrib-add-feat1