-1

Git newbie here.

I don't understand the need for a pull request vs a git push.

Why do i need to do a pull request to ask for a merge when i can push my changes to the master/origin ?

Could someone explain this to me ?

ATv
  • 65
  • 2
  • 11
  • Related, but not quite the same: see https://stackoverflow.com/q/49423624/1256452 – torek Dec 05 '19 at 00:29
  • Duplicate of [What is the difference between git push and git pull?](https://stackoverflow.com/questions/11240715/what-is-the-difference-between-git-push-and-git-pull) – TylerH Dec 05 '19 at 15:26

2 Answers2

1

A pull request is a special ref implemented by the hosting service. In Github, it's called pull request. In Gitlab, it's called merge request. In Gerrit, it's called pending change.

When a pull request is created, the hosting service records which target branch the pull request will be merged to after it's approved. With the pull request, many things could be done before it's really merged. The code could be reviewed. An automatic build/test job could be run.

Of course these things can also be done if you directly push the commits without any pull request. But, if anything wrong is found, you need either to rewrite the branch or make extra commits to fix it. It's a nightmare to rewrite a published branch, and extra commits will make the history untidy and confusing.

With the help of pull requests, we can make the commits as perfect as possible before they are really merged. It's like a draft. The goal is to improve the code quality, fewer bugs and less mess.

The pull request is not mandatory. It's just a useful mechanism in some workflows. It's completely okay not to use it if you don't think it's necessary.

ElpieKay
  • 19,185
  • 5
  • 22
  • 36
  • Ah ok, understood. So a pull request is more of a 'please review my changes' thing. But nothing prevents me from pushing to the master branch if i wanted to. I think if one uses Github you can define collaborators, i imagine if these are not setup i would not be able to write to the master/other branches? – ATv Dec 05 '19 at 07:15
0

If you have permission/access to push directly, you don't need a pull request at all. You would just push.

The point of the request is just that - to request that the owner of the remote repository pull your changes for inclusion.

Carl Norum
  • 201,810
  • 27
  • 390
  • 454
  • Gotcha. And you can define that access in most remote platforms like GitHub/bitbucket etc. What happens if you push and you don't have access, do you get an access denied? Also - what if you don't use a host platform like GitHub but a local repo, i guess there is no way to define access and everyone can just push. Many thanks! – ATv Dec 05 '19 at 07:19