Git: Incorporating multiple pull requests from the main project into your fork

Even where there is an existing git pull request (PR) addressing a bug fix or feature you might find critical for your use case, it is not uncommon for it to be awaiting a merge by the project owner.

As an example, the hellofresh company has done a great service to the community offering up various repository, including the ‘ansible-sssd-ldap‘ project that allows Linux users to authentication against an LDAP domain.  And that project has two pending PR that I would like to use immediately.  My best option is to talk to the owners of this repo and ask if there is any support I can lend in testing/documentation so these PR can be approved.

Doing this on the main project would be in everyone’s best interest.  If I  fork, it comes at significant expense to my organization to now maintain a vendored branch.  But if I need an immediate stop-gap measure,  I can fork the project and merge in each pull request (branches created in other repositories).

The first step is to create a fork of the main repository, so I have permission to merge and push.  From the github web UI, press “fork” on the original project site:

https://github.com/hellofresh/ansible-sssd-ldap

Then I need to locally pull down my personal fork so changes can be made.

# pull down my fork
git clone https://github.com/fabianlee/ansible-sssd-ldap.git
cd ansible-ssd-ldap

# validate source and show that branch is master
git remote -v
git branch

Now go to original project’s pull request page, and find the URL and branch name of each PR you want to pull. In this case we see it is:

  • https://github.com/orbatschow/ansible-sssd-ldap on ‘master’ branch which adds certificate support
  • https://github.com/dhardiker/ansible-sssd-ldap on ‘adaptavist’ branch which offers additional configuration pass through

First, let’s merge in the certificate support PR to our branch.

# prove that certificate path is not in code
grep certificate_base_path defaults/main.yml
# then pull the certificate support Pull Request
git pull https://github.com/orbatschow/ansible-sssd-ldap master
# now prove that certificate support is there
grep certificate_base_path defaults/main.yml

# commit the code from the PR
git commit -a -m "after commit of PR from orbatschow for cert support"
git push

Then we’ll merge the additional config PR to our branch.

# pull additional config PR
git pull https://github.com/dhardiker/ansible-sssd-ldap adaptavist

# Will report conflict with templates/sssd.conf.j2
# edit with vi, remove <<<< and >>>> lines and add jinja2 {{endif}}

# you will still get messages of "You have unmerged paths"
git status
# re-add to fix
git add templates/sssd.conf.j2

# then commit all changes
git commit -a -m "after commit of PR from dhardiker for additional passthrough params to sssd.conf"

# push back up to your fork in github
git push

 

Your repository now has the latest master code from the original project,  with the two PR applied.  Contact the original repo owners about merging this into the main project to reduce your maintenance costs.