Git forks to change a new product

I use git to manage the repository I'm working on.

The master branch is the main project. However, I am also working on a parallel product that is similar but not the same as the main product. He lives in branches named newproject .

The code base is very similar to the two, but newproject more truncated and has some basic changes. However, tons of window design elements, such as CSS, javascript, etc., are the same between two branches.

On the other hand, I deleted many files in the newproject branch that still exist in master .

I don’t want to merge these projects together, like the typical case with branches, where you create a branch to add a function or fix a bug, and then go back to master - these branches will live independently forever.

However, I still want to get any corrections from master in newproject , where there are still overlap / shared files.

If I just do

 $ git checkout newbranch $ git pull origin master 

I get a boat of conflicts because all deleted files appear as conflicts because they still exist in master .

Is there any way to handle this situation?

0
source share
2 answers

The achieved git effect submodules are exactly what you want: a collection of common code that several projects depend on, with fixes for common code distributed among all dependent projects. Submodules achieve an effect by separating the story from the general code, but this is only mechanics - and as soon as you see it, you will understand this by the natural right decision.

The submodule command itself exists to keep track of some petty household information (usually you can rm -rf * in the repo and not lose any committed state, but this is not true with nested repositories, so the command usually raises the .git dirs submodule such things ), but the submodule itself is nothing more than an embedded repository with its own history. If you go into it, the git commands don’t even know that it is a submodule of something because they don’t have to care: the submodule is how the repo is used, and not something internal to the repo itself.

  git init projectA cd projectA touch A # now there a file at the projectA root, # but the projectA repo doesn't know about it echo 'this content is in file "A" at the projectA root'> A git add A # content recorded, the index points to it git commit -m'A' # now projectA repo has a permanent record of the indexed state git init projectInner # now there an entire repo at the projectA root, # but the projectA repo doesn't know about it cd projectInner echo "Inner content" > Inner # a file at the inner repo, no repo knows about it git add Inner # content recorded, the inner repo index records it git commit -mInner # the inner repo has a permanent record cd .. git add projectInner # now the projectA repo knows about the inner, the content is recorded ... git commit -mInner # and now the projectA repo has a permanent record 

git add actual repo means recording its current state, as for adding a file or directory, but while the recorded state of the file is its full contents, and the recorded state of the directory is a recursive state from all its (tracked or not ignored) contents, the recorded state a repo is just his HEAD commit SHA - everything else is already written to that repo itself.

The payload here is that the git submodule is just a nested repo, which turns out that a nested repo can be very useful. As with the rest of git, what the submodule command actually does is brutal simplicity, all the apparent complexity lies in implementing what is most convenient in all the different situations in which it is so useful.

+1
source

after branching, you can make a git rebase master in your new project branch to move the split point to HEAD main branch. that this will be done is to reapply all the differences (which will be very easy and may not have serious, if at all conflicts, since most of the files are no longer in the newproject branch) from the newbranch split newbranch in addition to the changes made to main branch. Since newproject makes the inclusion of these files and other changes, everything should go smoothly (hopefully there are not too many conflicts). Check out the overflow information listed in the de facto git directory listed here.

0
source

Source: https://habr.com/ru/post/1243742/


All Articles