1

I'm working on a big project that has two "main" git branches: master and develop. The first one (master) is the production branch, the second one (develop) is the staging branch.

The last days I worked on develop and today I have to do a deploy. Some colleagues told me the steps to do that:

git fecth
git checkout develop
git pull origin develop
git checkout -b release/1.2.0
git tag v1.2.0
git push origin release/1.2.0
git push --tags

create a merge PR from release/1.2.0 to master
create a release for the new version specifying `master` as branch target and the changelog

It's the first time I need to do a thing like that and I'm not sure I understand all.

I try to explain what I understand:

git fecth # fetch all the remote changes
git checkout develop # I move to develop branch
git pull origin develop # fetch and merge develop changes in master branch (?)
git checkout -b release/1.2.0 # create the new branch release/1.2.0 and move inside it
git tag v1.2.0 # attach a tag to that branch (or commit?)
git push origin release/1.2.0 # push to master the new branch
git push --tags # push to master all the tags

create a merge PR from release/1.2.0 to master
create a release for the new version specifying `master` as branch target and the changelog

I'm very confused. I think I didn't understand what git pull origin develop does..

whitecircle
  • 237
  • 9
  • 34
  • Does this answer your question? [What is the difference between 'git pull' and 'git fetch'?](https://stackoverflow.com/questions/292357/what-is-the-difference-between-git-pull-and-git-fetch) – dahiya_boy Jun 14 '21 at 07:35
  • 1
    `git pull origin develop` **===>** fetch and merge changes from remote **develop** branch to local **develop** branch. – dahiya_boy Jun 14 '21 at 07:38
  • @dahiya_boy thank you, I've read that question. It was useful to me but not enough – whitecircle Jun 14 '21 at 07:47
  • As a side note, I'll mention that raw Git itself makes for a terrible deployment system. It has many of the pieces needed, but you have to manually assemble them into something usable. That's part of why the process you've shown above has so many steps. – torek Jun 14 '21 at 08:24

2 Answers2

2

You are not confused really. You described correctly what the commands do. The only thing you get wrong is your mention of the master branch, which never comes into play here. The third command just updates your local develop from the remote develop. Similarly, the pushes do not push to master. They push to origin, using the branch name specified in the command.

In additions, the commands themselves are sometimes silly. It is ridiculous to say:

git fetch
git checkout develop
git pull origin develop

The first and third commands needlessly do networking twice in a row. The better incantation is

git fetch
git checkout develop
git merge origin/develop

In general it should be possible in that last line to say simply git merge, but there is no particular need to do so.

matt
  • 515,959
  • 87
  • 875
  • 1,141
1

git pull origin develop is supposed to update your local develop branch with other commits pushed on that same branch.

I would recommend setting first:

git config pull.rebase true
git config rebase.autoStash true

That way, you would rebase your local develop commits (not yet pushed) on top of origin/develop, instead of merging origin/develop to develop: the history becomes more linear and clearer.

Also, I prefer git tag -m "v1.2.0" v1.2.0 or git tag -a v1.2.0 in order to create a full-fledged annotated tag, rather than a lightweight tag (bookmark): you can add more information to said tag (authoriship, date, relevant message)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250