1

I have a situation: My readme.md file in master branch also needs to be on gh-pages branch.
If I make any changes to the file on one branch, I need to replicate them on other.

Is there a way to have common git branch that can be referred by other branches?
Or track a file in two branches simultaneously?

See https://github.com/anupam-arohi/lv for more details on the issue.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Arohi
  • 111
  • 1
  • 3

1 Answers1

0

A branch is not "referred" by another, and a file with a new version in a branch will need to have said new version content "copied" somehow on the other branch.

You have two approaches:

  1. once you change the file in one branch, you checkout the other branch and copy it (I mention a general script in "How to update a file across all branches in a Git repository")
    In your case, that would be

    git checkout gh-pages
    git checkout master -- aFile
    
  2. Since the first option is not automatic, you could consider setting up a content filter driver through a .gitattributes declaration, a smudge script which, on checkout, would automatically copy the content of the file from the other branch.

    smudge
    (image from "Customizing Git - Git Attributes", from "Pro Git book")

That script would get the content of the file from the other branch and replace the content of that same file in the checked-out branch.

git show master:path/to/aFile > path/to/aFile
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250