N
N
nepster-web2014-08-01 02:30:06
git
nepster-web, 2014-08-01 02:30:06

How to merge branches in git?

I ran into such a situation, I have a project, for example, it consists of 2 parts. I created 3 branches, as a result it turned out like this:
test1 - for example, this branch works with part 1
test2 - and this branch works with part 2 of the application
development - this is the general branch into which we merge all changes and resolve conflicts
master - the main branch.
Now the situation is, for example, I work with the test1 branch, make changes, add features, and so on. Then I do the same with the test2 branch. Now the time has come when I need to update the project. I want to merge the test1 and test2 branches into the development branch, make sure everything really works, and update the master.
When I did this, I came across a number of unpleasant moments that I could not figure out. So a concrete example:
- in test1 I created an index.php file
- then I moved (git checkout development) to the development branch
- and tried to merge: git merge test1
Now this mean index.php disappeared from test1 and appeared in development. Is this how it should be?
Now I want to continue developing in test1 and I don't have my inde.php what should I do?
Please explain how to properly merge branches. I read this case in the docks, but did not understand why it happened.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EXL, 2014-08-01
@nepster-web

Why put different parts of the same project in separate branches? You seem to be misunderstanding the meaning of the branches that Git uses. A branch in this DCVS is just a pointer to the state of the working directory. And to implement the Work Flow that you described on the Git branches is not that difficult, but why and why torturing poor Git, which
will expand a subtree of one project to your working directory, then another. Firstly, this is terribly suboptimal in terms of the same performance, and secondly, you will get so completely confused, especially since you have also included merges between these branches in the workflow. Merger conflicts and difficulties can be achieved in this way a lot. Please take a look at the working approaches used for Git development:
If your parts of the project express very different functionality, then you can create two separate repositories (for example, fronted and backend), and then, if necessary, combine them into one Git superrepository as its submodules.
If one part is a dependency on another, then you should include that dependency as a submodule, or even as a subtree (see chapter 6.7 from Scott Chacon's Pro Git).
If this is still a monolithic project that has two parts, for example, the first part contains the implementation of the application logic in "./src/core", and the second contains the user interface in "./src/ui", then they do not need to be separated at all .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question