0

I have two branches:

  • Development
  • Feature

Development branch has one commit, namely 'init'. I branched feature branch of development branch, so feature branch should have the commit for 'init' as well.

I will make a change and commit this change to feature branch:

$> git checkout development
$> git commit -am "init"
$> git push
$> git checkout -b feature
$> git commit -am "change"
$> git push

Now another developer will add a change to development branch:

$> git checkout development
$> git commit -am "another change"
$> git push

Say that I would like to merge the feature branch into the development branch, will this cause any problems now that the development branch is ahead by one change because of what the other developer did?

$> git checkout development
$> git merge feature

If I would like to continue working on the feature branch, since something is still missing, the feature is still incomplete and I already merged feature branch into the development branch. Do I need to merge the development branch into the feature branch so that the feature branch is not missing anything? Or is this not necessary at all to continue my work?

Barrosy
  • 1,407
  • 2
  • 25
  • 56
  • @Schwern updated the question, notation mistake. I was playing around with git just not and it seems as though no problems should be caused. If someone could confirm my question that would be helpful. – Barrosy Oct 27 '20 at 20:39

1 Answers1

2

Say that I would like to merge the feature branch into the development branch, will this cause any problems now that the development branch is ahead by one change because of what the other developer did?

Git doesn't care, but the result of the merge will be untested. You need to test the result of the merge. Usually this is done with automated testing.

It's better to update the feature branch (see below), test the feature branch, and then merge. This is what Github Pull Requests and Gitlab Merge Requests do.

If I would like to continue working on the feature branch, since something is still missing, the feature is still incomplete and I already merged feature branch into the development branch.

You should not merge the feature branch until it is complete. Feature branches are for one feature. Once that work is done the branch is merged and deleted. If you want another feature, open a new feature branch. This is the Feature Branch Workflow.

If you merged by accident, and the merge has not been pushed yet, undo the merge. If it has been pushed, and it works, but it's just incomplete, open a new branch to continue your work. If it has been pushed and it introduces bugs, undo the merge and git push --force-with-lease to get rid of the bad merge.

Do I need to merge the development branch into the feature branch so that the feature branch is not missing anything? Or is this not necessary at all to continue my work?

Yes, you should bring your branch up to date with development by either merging in those changes with git merge development or rewrite your work on top of development with git rebase development. I recommend the latter, but it does require a solid understanding of Git.

Again, this is not strictly necessary, but periodically updating and dealing with changes from other developers in small chunks avoids a big surprise at the end.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • One question about pull requests I still remain with: what is the common way to deal with pull requests? Do you need to appoint someone to judge (or review) the contents of a pull request (e.g. whether it should be accepted and thus merged or refused and continue development)? I am aware that it's an entire different question and I will see if I will be able to find the answer. – Barrosy Oct 27 '20 at 21:17
  • 1
    @Barrosy That is a big question with many answers because reviews can serve many purposes. I can say that having ***anyone*** looking over your code helps. Even the most junior who is asking questions about the why and what will make you think twice about your code. Even reviewing it yourself ensures you've read over your complete change and thought about it. There is also automated code review, like Code Climate, to keep you honest on the basic stuff. – Schwern Oct 27 '20 at 22:37