Playing with git subtree. This project consist of two repos, this one and the fork repo
The purpose of this repo is to:
- Simulate the implementation of niteresting packages that the fork repo will include in it's subtree
- The fork repo should be able to receive updates from this repo
- The fork repo should be able to make local modifications
- The fork repo should be able to contribute some changes back to this repo
- Creat the init commit
- Fork repo init commit
- Fork repo includes only the
hello
package
# COMMANDS TO RUN IN THE FORK REPO!
# add upstream repo remote, create new tracking branch,
git remote add -f upstream-repo git@github.com:arnaubennassar/git-subtree-playground-upstream.git
git checkout -b feature/get-hello-package-from-upstram upstream-repo/main
# split off subdir of tracking branch into separate branch
git subtree split -q --squash --prefix=hello --annotate="[upstream repo] " --rejoin -b merging/hello-package
# add separate branch as subdirectory on master.
git checkout main
git subtree add --prefix=hello --squash merging/hello-package
# run go get to import the internal dependency from the upstream package that hello consumes:
➜ git-subtree-playground-fork git:(main) ✗ go get
# modify main.go to call the hello package
# run main.go to ensure it works:
➜ git-subtree-playground-fork git:(main) ✗ go run .
hello from the fork repo
hello
Hello from the internal dependency
- Add changes to the
hello
package in this repo, in this commit - Fork repo gets upstream modifications, in this commit
git fetch --all
# re-create tracking branch
git branch -D feature/get-hello-package-from-upstram
git checkout -b feature/get-hello-package-from-upstram upstream-repo/main
# update the separate branch with changes from upstream
git subtree split -q --squash --prefix=hello --annotate="[upstream repo] " --rejoin -b merging/hello-package
# switch back to main and use subtree merge to update the subdirectory
git checkout main
git subtree merge -q --prefix=hello --squash merging/hello-package
# run main.go to ensure it works:
➜ git-subtree-playground-fork git:(main) go run .
hello from the fork repo
BRAND NEW HELLO FUNC, but still... hello
Hello from the internal dependency
- Upstream modifies
hello
, in this commit - Fork repo gets upstream modifications, in a separated branch so we can do a PR to main
git fetch --all
# create update branch
git checkout -b feature/update-upstream
# re-create tracking branch
git branch -D feature/get-hello-package-from-upstram
git checkout -b feature/get-hello-package-from-upstram upstream-repo/main
# update the separate branch with changes from upstream
git subtree split -q --squash --prefix=hello --annotate="[upstream repo] " --rejoin -b merging/hello-package
# switch back to feature/update-upstream and use subtree merge to update the subdirectory
git checkout feature/update-upstream
git subtree merge -q --prefix=hello --squash merging/hello-package
# push changes
git push --set-upstream origin feature/update-upstream
# Open PR, approve and merge on GH
# switch back to main and use subtree merge to update the subdirectory
git checkout main
git pull
# run main.go to ensure it works:
➜ git-subtree-playground-fork git:(main) go run .
hello from the fork repo
Simple... hello
Hello from the internal dependency
- Fork repo modifies the
hello
package locally in this commit - This repo makes changes to
hello
that will create conflict later on, in this commit - Fork repo get changes from upstream as explained before, but needs to fix conflicts. PR to main
- Fork repo creates a PR to the upstream with the changes made in the previous step
git fetch --all
# create branch from main of the upstream repo
git checkout -b feature/push-to-upstream upstream-repo/main
# get changes from the fork main branch of the hello package
git checkout --patch main hello
# fix deps with go get
go get
# push changes
git add .
git commit -m "Contribute to upstream"
git push upstream-repo HEAD
# in the upstream repo create a PR from the branch with the same name (feature/push-to-upstream)