how to push all files in a folder to all git branches

2.7k views Asked by At

I have a lot git branches.

There's a directory/folder in which I keep apk files.

But whenever I add a apk/file and push it (1. git add, 2. git commit -m "", 3. git push), It gets pushed to the local branch in which i'm working.

Instead of this I want to push that file to all branches, so how can I do that?

Also already in that folder there are lot of apk files which are present only for that particular branch.

So how can I make them available for all branch(i.e. push all those apk files to all branches)?

2

There are 2 answers

0
VonC On BEST ANSWER

By default, you commit into a branch, and push to a remote repo all your commits.

If you want that commit (assuming it only includes your new file) to be visible in all other branches, one way would be to git cherry-pick that commit to the other branches.

If you just created that commit into master, you would switch branch and cherry-pick (the commit on top of) master:

git checkout another_branch
git cherry-pick master

However, this is not recommended if you intent to merge that other branch back to master at some point, as that would introduce a duplicate commit.

To read -- much more -- on that topic, see "git commit to all branches".

Merging your current branch to other branches is better (see "do a git cherry-pick in multiple branches"), but not always possible/wanted, as it would merge all commits from one branch to the other.

An actual proper solution would simply be to checkout to another branch and add your file (again there), make a commit (again) there.
And repeat for the other branches.

2
L. beom On

If you use the Source Tree application, it is possible to push multiple branches at once.

https://answers.atlassian.com/questions/314016/push-to-multiple-remotes-with-sourcetree