Reputation: 127
I have a project with two branches, one is master, and another is develop.
I am always on the master branch and when developers push their changes to develop branch I do git pull origin develop, and then git push origin master. That way I keep those branches up to date.
Another colleague of mine suggested I should do git merge origin develop, but I don't know what would be the difference between my way and his way since we both get the same result in the end.
Anyone with experience can weigh in and explain it to me?
Thank you!
Upvotes: 0
Views: 58
Reputation: 534893
My understanding is that you are acting as a kind of gatekeeper. There are two long-lived branches, master
and develop
. Development takes place on develop
; nothing happens on master
except that every so often you merge develop
into master
.
Since your server doesn't do pull requests, then what you are doing is fine:
git switch master
git pull origin develop
git push origin master
You friend who says to do git merge origin develop
probably doesn't say that. It makes no sense.
Your friend probably actually says or means git merge origin/develop
. That's a good thing to say, but it omits a step: get fetch
.
So you could instead proceed like this:
git fetch
git switch master
git merge origin/develop
git push origin master
From one point of view, that would not gain you anything you don't already have, because pull
is the same as fetch
followed by merge
of the named branch. However, I agree with your colleague: I like it better, because after the fetch
you can look at origin/develop
and think what's about to happen.
In my opinion, it is best to have a merge commit when you merge from develop
to master
, to clarify the history. To ensure that, I would recommend saying --no-ff
as you pull
or merge
.
Upvotes: 1
Reputation: 520878
Doing a git pull
is actually a composite operation. Doing git pull origin develop
means one of the following two things:
git fetch origin + git merge origin/develop (merge strategy)
- or -
git fetch origin + git rebase origin/develop (rebase strategy)
If your pull strategy already be set to merge
, which is usually the default setting, then you are already doing a merge with origin/develop
under the hood when you do your git pull origin develop
.
Upvotes: 0