git add common text for the same file in two branches with little variation

I have two branches. Both the branches have almost same code. But some files have some differences(with remaining common part). Now, if I want to add some 10lines of code that is common to both the branches, how should I add that same text to both the branches? Do I have to do it manually? Or there is some method .

Example :

Branch master :
a.txt file :

this is starting common line for both
this line belongs only to a.txt

Branch another:
a.file:
this is starting common line for both
This visible text is available only on branch ‘another’

From today onwards, most of my work is common to both the branches . So, how can I add to both the branches ? Do I have to do it manually or is there any some good way?

Will provide more information if necessary.

Thanks

  • Github enforce --no-ff when merging
  • npm install and build of forked github repo
  • Pathspec upstream/master is ambiguous
  • stash and then pop in git does an auto commit
  • Is it possible to 'fork a fork' in Github?
  • How can I stop Git from trying to push non-existent file?
  • Unchanged files showing in Git pull request
  • Get git contributors for a specific branch
  • One Solution collect form web for “git add common text for the same file in two branches with little variation”

    It essentially needs to be done manually in both branches, but there is a bit of a shortcut if you do it right – create a single commit that contains only that one modification, on one of the branches, then note the SHA of that commit, check out your other branch, and git cherry-pick <SHA>. That essentially takes the changes made in that one commit and applies them to the other branch as well. Saves a little typing, and reduces the chance of typos…

    Note, though, if you have a commit that contains other changes along with the one you’re interested in, it’s more difficult (but not impossible).

    Git Baby is a git and github fan, let's start git clone.