Skip to content

Instantly share code, notes, and snippets.

@adessein
Last active September 25, 2019 19:33
Show Gist options
  • Save adessein/aa61f1868765cafecfe6849e246c8c27 to your computer and use it in GitHub Desktop.
Save adessein/aa61f1868765cafecfe6849e246c8c27 to your computer and use it in GitHub Desktop.
Git subtree

This tutorial is inspired from this post on stackoverflow
I explain here how I subtreed the aircraft Citation X from the PAF Team addons repository

Definitions

There will be 3 branches involved:

  • master the local+remote master branch containing my version of the aircraft.
  • upstream-master the local branch tracking the entire upstream PAF addons repository.
  • upstream-CitationX the local+remote split branch, contains only the part of the upstream repository that is related to CitationX. This branch is a kind of inteface/filter.

git subtree split is the magic tool that is used to extract from upstream master only what is related to CitationX

Procedure

Initialisation

  1. Clone the entire repository using
git clone git://git.code.sf.net/p/pafteam/addons pafteam-addons
  1. Rename the master branch
git branch -m master upstream-master
  1. Create a branch upstream-CitationX that only contains the folder Aircraft/CitationX of the active branch
git subtree split --prefix=Aircraft/CitationX --onto upstream-CitationX --branch upstream-CitationX
  1. The remote origin is pointing to upstream, therefore we need to rename origin:
git remote rename origin upstream
  1. Create a Git repository that will contain fy fork/subtree of pafteam-addons CitationX and add as origin
git remote add origin [email protected]:adessein/citation-x.git
  1. Fetch and push the subtree branch
git fetch origin
git push -u origin upstream-CitationX
  1. Create my master branch and push it to origin
git checkout -b master
git push -u origin master

Fetch upstream update

  1. Checkout the upstream-master branch and pull
git checkout upstream-master
git pull
  1. Update the filtered branch upstream-CitationX
git subtree split --prefix=Aircraft/CitationX --onto upstream-CitationX --branch upstream-CitationX
  1. Merge upstream-CitationX into master
git checkout master
git merge upstream-CitationX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment