Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit to multiple branches at the same time

Tags:

git

I want to make a single commit on different branches at the same time, since, in my project, I have different branches for different clients.

Say, I have made a new feature commit on Branch A. Can I also make this commit on Branch B, Branch C and D at the same time as well? Is there any short cut command for this? This is very troublesome to checkout one branch, and cherrypick the commit everytime, sometime, if the commit is necessary on many branches, it would be a nightmare for me.

Any simple bash script for this operation?

There is a similar question in there. but rebasing is not that I want.

like image 959
TheOneTeam Avatar asked Aug 31 '11 15:08

TheOneTeam


People also ask

Can two branches refer to same commit?

Yes, two branches can point to the same commits.

How do I commit to all branches?

If you use git branches a lot, you'll often push each branch after each commit. Instead of pushing every single branch you can do git push --all origin . This will push all commits of all branches to origin.

Can I work on 2 branches simultaneously?

You can have many branches in your repository, but only one of these will be "checked out" as the working-tree so that you can work on it and make changes. git worktree adds the concept of additional working trees. This means you can have two (or more) branches checked-out at once.


1 Answers

The cherry-pick feature will do the job and will only apply the last commit:

Considering branches A, B

git checkout A git commit -m "Fixed the bug x" git checkout B git cherry-pick A 

hope this helps!

like image 135
spoutnik Avatar answered Oct 11 '22 17:10

spoutnik