Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forking and adding a feature from the branch on a fork: Git subtree #10

Open
ddkapan opened this issue Mar 22, 2022 · 0 comments
Open

Comments

@ddkapan
Copy link
Collaborator

ddkapan commented Mar 22, 2022

A QUICK FYI:
Git subtree to add features from one repo to another and preserve commit history, or

How to fork a repo and add a feature from a new feature branch on the fork:

  1. Forked the repo COMB to COMBddkapan on personal GitHub & clone from GitHub to your favorite place for git projects (mine is called GitHub)
cd ~/GitHub
git clone https://github.com/ddkapan/COMB COMBddkapan
  1. Change directory to the local copy of CAPLES (the source repo)
cd ~/GitHub/CAPLES
  1. Then split out the feature as a branch with the feature name as a subtree
git subtree split -P point_counts -b point_counts
  1. Change directory to the COMBddkapan & make a feature branch
cd ~/GitHub/COMBddkapan
git branch point_counts
git checkout point_counts
  1. Add the subtree to COMBddkapan
git subtree add -P point_counts /Users/dkapan/GitHub/CAPLES point_counts --squash

Note --squash(ing) is recommended to compress the source repo history from the subtree (could have done this at first) similar to rebase.

  1. Push to upstream branch.
git push --set-upstream origin point_counts
  1. Then, got to GitHub & make a pull request to developers (us) of the original COMB repo.
  • Verify that the merge-pull worked: first check online. Then pull updates locally and run the code.
  • (Back-out by resetting if necessary: e.g. git reset --hard HEAD~1) #careful
  1. Once verified, return to the original source repo (in this case the local copy of CAPLES)
cd ~/GitHub/CAPLES
  1. and delete the split out branch that you never even pushed to the remote
git branch -D point_counts
  1. check that all is ok in the original source repository (CAPLES) and the new updated destination public repo (COMB), for instance, run
git status
git log 
#etc...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant