7

Is it possible for me to push a commit from one Git repository into a branch of another Git repository?

So for example, I have a commit aaaa in Repository A. Commit aaaa is in a branch called "Testing". I want to push commit aaaa into a branch called "Stable" which is in another repository called Repository B. When pushed into Repository B from A, the new commit to Repository B should be an exact image of commit aaaa, ie, replacing all of the files in the branch "Stable" in Repository B with the ones from A.

If this is possible, how can I do it?

Carven
  • 14,988
  • 29
  • 118
  • 161

1 Answers1

6

Try this:

git push repositoryb aaaa:Stable

I am assuming repositoryb is a remote pointing to the other repo. And if you haven't come to grips with git, the above pushes the commits upto aaaa and not just aaaa.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • The situation I have now is that RepositoryB is a Git address. I'm using BitBucket, and every repository has its own address given by them. So, before running this command, should I be in RepositoryA and checked out in the branch "Testing"? – Carven Mar 25 '13 at 13:37
  • The above solution doesn't care about your Testing branch. But of course, you have to be in the repositoryA. – manojlds Mar 25 '13 at 13:38
  • Since this command will push all earlier commits in RepositoryA too which may be too much to push in my case, is it possible to set a range of commits to push from RepositoryA? Say like aaaa1 to aaaa3 into RepositoryB of branch Stable? Also, I would replace the RepositoryB with its Git address, right? – Carven Mar 25 '13 at 13:42
  • 1
    I get an error saying that this is a non-fast-forward error. It says that "Updates were rejected because a pushed branch tip is behind its remote". But all I really want, is to push and overwrite everything from commit `aaaa` into RepositoryB's `Stable` branch. – Carven Mar 27 '13 at 12:01
  • Do `git push -f repositoryb aaaa:Stable` – manojlds Mar 27 '13 at 15:26