1

I know I can graft one branch of one git project (says 'old') to another one (says 'new') by running this command:

 cd old # location of the 'old' repo
 git push git:git@github.com:dude/new.git a-branch 

However I do not want to push all the history of the branch to the new git project. I only want to include a subset of the commits in this branch.

How can I do it?

Anthony Kong
  • 33,453
  • 37
  • 154
  • 277

2 Answers2

1

If you only want to push a subset of the history you must create a branch that contains only the subset of commits you want to push. So create a new branch based on your current

git checkout -b subsetOfCommits

than rebase in interactive mode.

git rebase -i firstCommitYouWantToChange

Use the rebase interactive editor and squash, fixup, move or delete the commits.

Finally push that branch to wherever you want.

René Link
  • 43,842
  • 12
  • 98
  • 127
0

You simply can specify the SHA1 you want to limit that branch to:

git push git:git@github.com:dude/new.git <SHA1>:abranch

All commits up to that <SHA1> will be pushed to a remote branch 'abranch' on new.git repo.
See for example:

Community
  • 1
  • 1
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755