1

I am working on a project with many branches of different experiment settings. Now I update the "readme.md" and want to copy it to every branch. Instead of switching to every single branch and manually paste it, if there a command to do this in one shot?

Wenqi
  • 11
  • 1
  • 1
    No there's not. But what do you mean by "paste it"? You'd have to make a commit with the modification and merge or cherry-pick it everywhere needed. No "pasting" involved here. – Romain Valeri Aug 05 '19 at 13:52
  • 2
    There is no way to do this, nor does it even make sense to speak of broadcasting _files_ in Git, because branches interact with each other via _commits_, which are snapshots of _every_ file in the repository. The typical way you would handle your use case is to make a change to the master/source branch to add this file, then merge or rebase with any other dependent branches which need this added file. – Tim Biegeleisen Aug 05 '19 at 13:54
  • You might find this useful: https://stackoverflow.com/a/36130087/1698736 – cowlinator Sep 08 '20 at 18:49

1 Answers1

1

This is not possible for Git. To understand why this is not possibe you should read this document on Branches. Basically the idea is that branch in git is just a simple movable pointer that points to a specific commit. Since when You have updated Your readme.MD, You have created a new commit then there is no simple way to "broadcast" those changes to another branches. You would have to move the pointers of all branches to the commit in which You have updated the readme.MD but this would simply make no sense as all branches would make no sense. Probably the fastest way to achieve this is to use cherry-pick command. But this would require You to do this on each branch separately.

Community
  • 1
  • 1
Dominik Wosiński
  • 3,769
  • 1
  • 8
  • 22
  • That's so sad, but it's good to upgrade my understanding of branches anyway. Thanks a lot! – Wenqi Aug 05 '19 at 17:51