0

I have two remote origin and another repositories and, for example, commits history on origin:master repo:

A - B - C - D - E - F

another is empty repo.

Need to push only last two commits E - F to another:master i.e.:

origin:master: A - B - C - D - E - F
another:master: E - F 

How I can do that with possibility after to push in this two remotes without rebase or something else?

Anton Lashkov
  • 280
  • 3
  • 10

1 Answers1

1

You would need a git history with an initial empty commit and two branches: one (your current master) pointing to F and another one pointing to the empty commit.

Check out the branch pointing to the empty commit, cherry-pick E and F, and push this branch to your another remote. As you make changes that you want in the another repository, you'll simply cherry-pick them over.

So, after having created the initial commit:

git checkout -b another-branch <<SHA of empty initial commit>>
git cherry-pick <<SHA of E>>
git cherry-pick <<SHA of F>>
git push another another-branch
Community
  • 1
  • 1
houtanb
  • 3,852
  • 20
  • 21
  • This solution oblidge me to have two branches and do `cherry-pick` on every commit in `master` after `F`, is there exists simpler solution? – Anton Lashkov Nov 02 '15 at 13:39
  • No, because git keeps track of the **history** of a project. In your example, `E` depends on everything that has come before it, even if it's a commit that contains a new file that has not been touched by a previous commit. See [this post](http://stackoverflow.com/questions/3230074/git-pushing-specific-commit) – houtanb Nov 02 '15 at 13:48