87

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
  • 91,013
  • 29
  • 181
  • 233
MeesterPatat
  • 2,441
  • 7
  • 29
  • 54

5 Answers5

122

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
  • 91,013
  • 29
  • 181
  • 233
43

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
git push origin feature_branch
zdrsoft
  • 1,877
  • 16
  • 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
13
git pull origin develop

Since pulling a branch into another directly merges them together

11
git fetch && git merge origin/develop
Dharman
  • 26,923
  • 21
  • 73
  • 125
Sebastian Diez
  • 144
  • 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,696
  • 4
  • 33
  • 67