Anton Lashkov
Anton Lashkov

Reputation: 280

Push only some commits to another git repository

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?

Upvotes: 0

Views: 433

Answers (1)

houtanb
houtanb

Reputation: 4100

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

Upvotes: 1

Related Questions