-1

I have two branch:

  • develop
  • myBranch

I'm working on myBranch and some other makes a push on develop.

So now I should merge my branch "myBranch" into develop.

So I'll checkout on develop, i'll make a pull and then can I merge "myBranch" ?

git checkout develop
git pull 
git merge myBranch

it is rigth in your opinion?

Jack23
  • 1,368
  • 7
  • 32
  • 3
    Does this answer your question? [What is the best (and safest) way to merge a Git branch into master?](https://stackoverflow.com/questions/5601931/what-is-the-best-and-safest-way-to-merge-a-git-branch-into-master) – nitishagar Sep 23 '21 at 13:21
  • could you add the commands you were thinking of using? I do think this is a duplicate – rhavelka Sep 23 '21 at 13:43
  • I have wrote the command that I would do, but i'll edit – Jack23 Sep 23 '21 at 13:44
  • Yes it looks fine. Also, you will probably want to pull develop into your branch first, you can do that in your branch by using `git pull origin develop` – gkpln3 Sep 23 '21 at 13:48
  • Unless you are done with `myBranch`, you should merge `devel` into `myBranch`, or rebase `myBranch` on top of `level`. – chepner Sep 23 '21 at 13:48
  • If you weren't ready to merge `myBranch` into `devel` before the push to `devel`, the push hasn't changed that. – chepner Sep 23 '21 at 13:49
  • @chepner the branch that should be always updated is develop, you suggest anyway to do in this way? – Jack23 Sep 23 '21 at 13:49

2 Answers2

1

You should first merge devel into myBranch until you are ready to incorporate your changes into devel. Another developer pushing to devel does not require you to do the same immediately.

# Get any new changes from the remote
git fetch

# You don't necessarily need to update your copy of devel yet;
# just merge the new commits from devel into myBranch
git merge origin/devel

# continue working on myBranch

# Time to merge your changes to devel. 
git checkout devel
git pull
git merge myBranch

Merging devel into myBranch while you develop lets you resolve any merge conflicts as they come along, rather than having to resolve all of them at once when you finally merge myBranch into devel. If you merge often, you should minimize, if not eliminate, the merge conflicts during git merge myBranch.

chepner
  • 497,756
  • 71
  • 530
  • 681
  • So in my branch: "myBrancH" i should merge orgin/develop before? It doesn't overwrite the changes I made right? – Jack23 Sep 23 '21 at 13:56
  • 1
    Overwrite, no, but there may be merge conflicts to resolve where both `devel` and `myBranch` have made similar but different changes. – chepner Sep 23 '21 at 13:59
  • But you still need to *test* your code following the merge. A merge may not overwrite your changes, but it can make things you assumed no longer be true. – chepner Sep 23 '21 at 14:01
  • ok , ty so much :) – Jack23 Sep 23 '21 at 14:03
0

You don't need to do the git pull, that would be pulling the changes from remote. If you want to just merge, then it's:

git checkout <branch to merge into>
git merge <feature branch>
Salaah Amin
  • 382
  • 3
  • 14