[ad_1]
Asked
Viewed
16 times
Scenario 1:
- I have ‘master’ branch in both local and remote repositories
- I create a ‘feature-1’ branch and make few commits in it.
- Merge ‘feature-1’ branch in to ‘master’ branch
- push changes to remote ‘master’ branch
Scenario 2:
- I have ‘master’ & ‘feature-1’ branches in both local and remote repositories
- I make few commits in local ‘feature-1’ branch
- I push those changes to remote ‘feature-1’ branch
- Merge ‘feature-1’ with ‘master’ on remote server (GitHub)
Which approach is better? I am confused.
1
The end result is effectively the same, however if you have to abide by a review process, you’ll want to to push your feature branch and then create pull or merge request and then have it merged remotely after it was reviewed and approved.
Simply scenario 2, because more colleagues get a chance to review it if needed, also to run any needed pipelines on push etc.
Just to clarify:
The question is tagged as git
. On those terms, scenario 2 does not exist. Git will absolutely refuse to perform a merge at the server side. It has no provision for such a thing; indeed, it is forbidden. That is why you cannot push to a branch that has commits you don’t have locally.
Some Git hosting sites, such as GitHub, have created a mechanism termed a “pull request” or “merge request” where it looks like a merge is being performed on the server side. This mechanism involves not only the final merge but the display of the diff and the ability to comment upon it before the merge. This is to permit multiple collaborators to review one another’s work before the merge takes place. Many workplaces install a rule at GitHub saying that the merge will be forbidden until the branch has been explicitly approved by a collaborator.
So the rule is simple:
-
If you are working alone, merge locally.
-
If you share this repo with other collaborators who will be wanting, independently, to create branches to be merged into the main branch, then by all means take advantage of pull/merge requests on the server side to facilitate collaboration.
Not the answer you’re looking for? Browse other questions tagged git or ask your own question.
[ad_2]