2

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)?

Shirish Herwade
  • 11,461
  • 20
  • 72
  • 111
  • You don't push files. You push commits. If you want to apply a commit from one branch on another, you can use cherry pick. – avmohan Dec 26 '16 at 20:55

2 Answers2

2

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

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

L. beom
  • 53
  • 8
  • will try using 'Source Tree application', i haven't used it before... BTW thanks for showing some hope :) – Shirish Herwade Dec 27 '16 at 06:16
  • 1
    We need to keep our vocabulary clear here. You add commits to branches, and then push to the remote repo. Pushing multiple branches doesn't help you until you have committed the changes you want (e.g. the new files) to each branch. I like the "cherry pick" suggestion made above by v3ga – Randy Leberknight Dec 27 '16 at 19:26