Alexander Mills
Alexander Mills

Reputation: 100406

"push" changes on branch A to two other branches in same git repo

Instead of pushing to remote repo, is there a way to push changes for a certain branch to other branches in the same repo?

The rationale is that I want to avoid having to checkout the other branches and then run merge for each other branch

Normally, I would do

git commit -am "making changes to branch c"
git checkout a
git merge c
git checkout b
git merge c

I would rather not have to checkout the other branches, and just "push" the changes from c to the other branches.

something like:

git commit -am "making changes to branch c"
git push local a b   // not right at all

Hope it makes sense.

The only stuff I see online is how to push to a different branch if it's it a separate repo (a remote repo for instance).

Upvotes: 0

Views: 50

Answers (1)

torek
torek

Reputation: 489848

Yes, you can do this. The trick to know is that a "remote" named . refers to your own local repository.1 Hence:

git push . HEAD:a HEAD:b

or:

git push . c:a c:b

(assuming HEAD names the same commit as c) does this. Note that the adjustment to a and/or b must be a fast-forward, as would be required with any remote. You can force the push but this has the same effect as with any remote (i.e., discarding some commits: pushing with --force is much like using git reset).


1This falls naturally out of the fact that any path, such as git push /some/where/over/there, is treated as a file URL, and . is a path, and . means "the current directory", and the push starts from the top of the repo, so the "other" repo is right here where ours is.

Upvotes: 1

Related Questions