108

I checked out a feature branch from develop called branch-x. After a while other people pushed changes to the develop branch.

I want to merge those changes into my branch-x. However if I do

git merge develop 

it says "Already up-to-date" and doesn't allow me to merge.

git diff develop shows that there are differences between branch-x and develop.

How do I merge develop into branch-x?

Maroun
  • 94,125
  • 30
  • 188
  • 241
MeesterPatat
  • 2,671
  • 9
  • 31
  • 54

5 Answers5

140

You should first pull the changes from the develop branch and only then merge them to your branch:

git checkout develop 
git pull 
git checkout branch-x
git rebase develop

Or, when on branch-x:

git fetch && git rebase origin/develop

I have an alias that saves me a lot of time. Add to your ~/.gitconfig:

[alias]
    fr = "!f() { git fetch && git rebase origin/"$1"; }; f"

Now, all that you have to do is:

git fr develop
Maroun
  • 94,125
  • 30
  • 188
  • 241
81

Step by step self explaining commands for update of feature branch with the latest code from origin "develop" branch:

git checkout develop
git pull -p
git checkout feature_branch
git merge develop

If there are any merge conflicts after "git merge" CMD, fix the merge issues manually & add those manually merged file(s) & commit

git add <mergedFile>
git commit -m "Merged develop to feature_branch"

Finally push the merge to remote:

git push origin feature_branch
Saurabhcdt
  • 1,010
  • 1
  • 12
  • 24
zdrsoft
  • 2,417
  • 19
  • 10
  • 2
    What does the `-p` option do? I can't find it in my manpage. – cmaster - reinstate monica Aug 17 '20 at 09:24
  • Just commit whatever you have in your feature_branch and then try this answer. – Deepesh kumar Gupta Aug 17 '20 at 17:51
  • 2
    git pull -p -p is the same as --prune, this option do cleaning of outdated branches. You could define automatic prune instead usage of parameter: https://stackoverflow.com/questions/18308535/automatic-prune-with-git-fetch-or-pull In the example above -p option could not be used. – zdrsoft Aug 18 '20 at 10:10
  • 2
    If there are any merge conflicts after "git merge develop" CMD, fix the merge issues & add those manually merged file using "git add ". Then commit the changes "git commit -m "Merged develop to feature_branch" & then execute last CMD to push changes to origin feature_branch. Could not edit the answer due to "Suggested edit que is full" error. – Saurabhcdt Jun 16 '22 at 15:06
  • @Saurabhcdt you can edit now – hakima maarouf Aug 15 '22 at 11:38
  • None of theses solutions worked for me either. If I do a compare between develop and feature branch, expected changes are shown. But when I do a merge using VS 2022 or manually, nothing changes. Had to manually update one script to hopefully get past issue. – Russ R Aug 25 '23 at 13:34
19
git pull origin develop

Since pulling a branch into another directly merges them together

14
git fetch && git merge origin/develop
Dharman
  • 30,962
  • 25
  • 85
  • 135
Sebastian Diez
  • 172
  • 1
  • 4
6

Initially my repo said "Already up to date."

MINGW64 (feature/Issue_123) 
$ git merge develop

Output:

Already up to date.

But the code is not up to date & it is showing some differences in some files.

MINGW64 (feature/Issue_123)
$ git diff develop

Output:

diff --git 
a/src/main/database/sql/additional/pkg_etl.sql 
b/src/main/database/sql/additional/pkg_etl.sql
index ba2a257..1c219bb 100644
--- a/src/main/database/sql/additional/pkg_etl.sql
+++ b/src/main/database/sql/additional/pkg_etl.sql

However, merging fixes it.

MINGW64 (feature/Issue_123)
$ git merge origin/develop

Output:

Updating c7c0ac9..09959e3
Fast-forward
3 files changed, 157 insertions(+), 92 deletions(-)

Again I have confirmed this by using diff command.

MINGW64 (feature/Issue_123)
$ git diff develop

No differences in the code now!

bPratik
  • 6,894
  • 4
  • 36
  • 67