Sergio Costa
Sergio Costa

Reputation: 769

Git merge deleting code that should stay

When merging branches, Git automatically removes code that shouldn't be removed. Basically we have two main branches: MASTER and DEVELOP.

All new code starts in other branches, that usually refer to the issue or new feature. The problem happens when we try to merge this feature or hotfix branch into develop.

Our daily activities is: (current branch develop):

git pull origin develop
git checkout -b some-feature.

Both programmers add some code and commits (we commit more than once daily). At the end of the day we try to merge our things. First, programmer A makes a push.

  git add .
  git commit -m 'last commit before push'
  git checkout develop
  git merge some-feature
  git push develop

No problem so far. Then programmer B tries to do the same, but he has to make a pull first!

  git add .
  git commit -m 'last commit before push'
  git checkout develop
  git merge some-feature-b
  git pull origin develop

Git successfully fetches and merges origin/develop. Some conflict may happen, no problem with conflicts. Our problem is that Git removes code that shouldn't be removed and we have no chance to tell it not to.

What are we doing wrong?

Upvotes: 4

Views: 5648

Answers (1)

VonC
VonC

Reputation: 1328562

I would pull first, then merge.

git checkout some-feature
# work
git add .
git commit -m 'last commit before push'

git checkout develop
git pull develop
git merge some-feature

That way, you are merging your local some-feature branch in an up-to-date develop branch.

Upvotes: 3

Related Questions