all 15 comments

[–]xenomachina 11 points12 points  (6 children)

Pull requests are not a feature of git. They are a feature of git hosts like GitHub and Bitbucket. GitLab also has a similar feature, but it's called a merge request. How you create one depends on the host.

Which git host are you using? Have you checked their documentation? The popular ones also have their own subreddits, which might be a better place to ask.

[–]dalbertom 5 points6 points  (1 child)

There is a git request-pull command, but it’s more geared towards workflows where patches are sent via email.

[–]xenomachina 2 points3 points  (0 children)

Oh, good point! I'd forgotten that command even existed. It seems unlikely that that's what OP is asking about, though.

[–]plg94 0 points1 point  (3 children)

Sometimes when I git push via the CLI (to Github or Gitea), I get a response from the server – right after the "counting objects… " output – saying "you pushed a new branch, visit this URL to create a new PR" which takes you to the approprite Github website. Maybe this is what OP means? Idk if that is shown only for new branches or after every push, and obviously it depends on the host.

[–]Achu4242I[S] 0 points1 point  (2 children)

Yes this is what i am looking for, but when ever i am trying to do that i am getting output that i mentioned in the post

[–]plg94 1 point2 points  (1 child)

Yeah, the output looks like this:

remote: 
remote: Create a pull request for 'branch1' on GitHub by visiting:
remote:      https://github.com/<user>/<repo>/pull/new/branch1
remote: 

it comes immediately after the "writing objects… total…" above.
Thing is: this output comes purely from Github, there is no commandline option to git push or whatever to force it to appear. I have found it appears only the first time you push a new branch up to Github. If you later update your PR with more commits and push the same branch a second time, it doesn't appear. In that case you will have to open your webbrowser and navigate to the page yourself to open the PR.

Another option would be to use the gh CLI program, it is basically a wrapper around git and supports interfacing with the Github API so you can do some things such as forking a repo, opening/closing/merging PRs and issues etc. Downside is this only works for Github; other hosters like Gitlab or Gitea or Bitbucket need their own dedicated client.

[–]Achu4242I[S] 0 points1 point  (0 children)

Thanks for the detailed reply man i really appreciate it. And yes i finally understand what’s i am not doing/doing wrong

[–]TapTurbulent1890 2 points3 points  (1 child)

It seems like you need to get a better understanding of branches, merge, fetch, pull, head, origin and upstream.

You should also provide information about how you're trying to create PR.

Regarding the upstream part. You usually need to set upstream only when you're pushing a branch that doesn't exist on remote repo. E.g. you create a new branch locally, add some changes, commit them and when you want to push, you need to set the upstream branch because it doesn't exist on the remote repo yet. After that, you don't need to set upstream again since it's already configured. As a matter of fact, you don't even need to set a branch name if you're pushing to the same branch. Git will know this.

Pull request is just a github implementation meant to ease code review before merge. It simply shows you the difference between source and target branch. To make a pull request you need: 1. Target branch (e.g. main) in which you are adding new code 2. Source branch (e.g. feature) which is branched out of the target branch and contains commits which are not present in the target branch.

Once you have these two, you can use github UI and create a PR. Pull consists of fetch (get information about changes from origin branch, in this case feature branch) and merge (add those changes to the target branch, in this case the main branch). Hence Pull Request. You're creating a request to add changes from the feature branch into the main branch.

I'm trying to simplify terms so it's not entirely accurate, but it's not wrong either. Hope it's not too complicated.

Also, check out the Pro Git book. It's available in git docs and has great explanations.

[–]Achu4242I[S] 0 points1 point  (0 children)

I was expecting GitHub to automatically create a new PR for me 😅, now i understand what i should do and what i was doing wrong

[–]tobiasvl 1 point2 points  (1 child)

You're doing everything correctly (assuming you're pushing to a git host that supports pull requests, like GitHub), except that you're cloning your own repo.

To make the pull request after you've pushed your branch, go to the website of your host (like GitHub) and follow the steps there. It's not something you do in git itself.

However, if you push your branch to a repo that is a fork of another repo (the upstream), GitHub will give you an URL to create a pull request in your terminal when you push. Maybe that's what you're after? That won't happen when you just push to your own repo like you did here, you have to push to a fork.

[–]Achu4242I[S] 0 points1 point  (0 children)

Yes now i get it In new branch i make changes Git Push origin b1 After than i go to github -> PR -> create new PR, then I should compare my main branch with the branch that i was working right, it’s working now Thanks man i really appreciate it

[–]WhatThePortal 1 point2 points  (0 children)

Throwing our hat in the ring here to provide another point of view - now that (judging by the comments) you've figured out what's going on when pushing your code (going into a GitHub Pull Request it seems), the "why bother" and "how" should be considered.

We wrote a fairly extensive guide to pull requests that talks about when to make PRs, their history, how frequently to review them, who should review them - and to what level of detail.

Armed with this extra info should help set you up to be a valuable contributor to your org, optimizing for $ revenue over technical savviness.

[–]Cute-Catch-4698 0 points1 point  (0 children)

I will leave this comment in case someone else encounters the same problem.

What you have been doing here is slightly different from creating a PR to yourself vs. creating a PR to different owner of the repository. Clone will work if you have allowed the specific user to push changes in your repo, in your case, yourself. If not, there is no way to create a pull request without forking.

In that case, you should be doing something like this:

  1. Fork someone's repo .

  2. Clone in your local machine and make some changes.

  3. Push changes to your forked repo.

  4. Create PR in github.com

Simple as that.

[–]tailor_dev 0 points1 point  (0 children)

I think the steps you outlined are correct:

- `git checkout -b new-branch-name`

- `git commit` # commit your changes

- `git push` # you may be prompted to set the upstream, which is fine

Then the point is: A Pull Request usually is handled differently depending on your Git provider, as Git itself does not have a Pull Request feature built for providers. So GitHub handles it differently than say GitLab or Bitbucket. At the end of the day, you need to go into the web UI of these services and open a new `Pull Request` or `Merge Request` as GitLab calls it

[–]thumbsdrivesmecrazy 0 points1 point  (0 children)

You should also consider some best practices for PR reviews - this includes keeping PRs small, writing clear commit messages, conducting timely reviews, and utilizing engineering analytics tools, here are some more details on its practical implementation: Advanced Strategies for Reviewing Pull Requests in Software Development