Do I need to checkout and delete the remote git branch before merging it?

My usual process for merging into develop

with my branch feature\my-feature

:

name@home ~/myRepo (feature/my-feature)
$ git checkout develop
$ git pull
$ git checkout feature/my-feature
$ git merge develop
$ git mergetool

      

Could this be replaced with:

name@home ~/myRepo (feature/my-feature)
$ git fetch
$ git merge origin/develop
$ git mergetool

      

Is getting fetch

enough information about the changes from the remote origin/develop

so that I can merge with origin/develop

instead develop

?

Wrong practice to have feature/my-feature

before develop

with changes from the remote origin/develop

?

+3


source to share


2 answers


You can directly pull

remote branch develop

, but you may need to specify the remote repository (in your case origin

):

git checkout feature
git pull origin develop

      



This will commit the merge where the message indicates origin/develop

.

Without mentioning the remote repo, I'm afraid that the merge part will merge pull

your local branch develop

, not the checked out one. But try it!

+2


source


As indicated in this matter , git pull

- it is simply git fetch

followed git merge

.

I find it easier to think in such terms.

I personally prefer to fetch remote branches rather than pull them, because automatic merging, forced with help git pull

, is not always necessary.

This is what my typical workflow looks like: I always start new features from a branch origin/develop



git checkout develop
git fetch origin
git reset --hard origin/develop
git checkout -b new_feature_branch

      

This will ensure that I am on the very latest development branch.

Why is it better than pull

? Because it prevents merging on checkout and helps maintain a clean git history.

0


source







All Articles