I’m new to git; I know the basic commands, but I’m not as familiar with the optimal way to organize projects.
I have two versions of a file that do nearly the same thing. The only difference between the two files is the way that they scan a particular file, and the differences are confined to one area of code. As I add functionality to one, I could just copy and paste the same changes into the second file, but I imagine that this is what good version control is meant to simplify.
My best guess is that I should create a second branch (say, ‘branch_B’) and keep a copy of the file with the same name in both branch_A and branch_B (so that they can be merged easily). But then, when I merge, won’t I end up with a weird combination of the two files in the master branch, rather than an updated version of the second file?
Avoiding duplication of code is something you should do by refactoring your code. Version control is not meant to be a substitute for this.
Git can efficiently store duplicated content, but that isn’t the point. Once you have checked out code from the repository into your working tree, you will still have duplicate code to work with. Using your version control tool in this way isn’t going to make anything more maintainable for you.
See: Code reuse