0

Iam trying to add file in all branches of git :

cd <git url>
for remote in $(git branch); do
git checkout --track $remote
cp -r /path/of/file . #copy file from local to current directory
git add .
git commit -a -m "file added"
git push origin -u $remote
done

how to implement this?

AD7six
  • 63,116
  • 12
  • 91
  • 123
  • 2
    Why are you trying to do that - the question as asked isn't how git works, but you can add it and cherry-pick the commit to all branches which would do the same thing. Again: why? – AD7six Jun 09 '20 at 09:19
  • 2
    Perhaps better to create the commit that add the file in one branch and then checkout the other branches one by one and cherry-pick the commit with its hash. – Philippe Jun 09 '20 at 09:20
  • i want to keep one file in all branches as common, is there any other way like i want to keep abc.txt in all branches of my git repo ! – Sudhanshu Mishra Jun 09 '20 at 09:22
  • 1
    You haven't answered why, and that's pretty important to understanding what you're doing. – AD7six Jun 09 '20 at 09:23
  • 1
    and you can, by committing it to each branch, and cherry-picking or merging that initial commit and any subsequent changes from your 'master' branch to all your other ones. – underscore_d Jun 09 '20 at 09:24
  • @Philippe cherry pick holds true in this for loop logic ? if not what modifications needs to be done ? – Sudhanshu Mishra Jun 09 '20 at 09:25
  • @AD7six actually i want to have yml file in every branch so that i can use it for deployment by choosing respectice branch to deploy on azure devops – Sudhanshu Mishra Jun 09 '20 at 09:28
  • I suggest you do `git commit -a -m "make deployable"` and then cherry pick that to each branch. Unless you have 10s or 100s of branches there isn't any complexity to deal with - and if you do have - that info should be in the question. Please self-answer :). – AD7six Jun 09 '20 at 11:27

0 Answers0