Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Pull Request using the new github cli, to a remote repo without pushing a remote branch too?

I am trying to figure out how to make a PR to my remote repository from a local branch (or even from local master/main branch). However, no matter what I do I get the following error:

Attempt from local main:

(master)$ gh pr create --title "Adding readme" --body "Testing pr from cli" --head armsp:feature

Creating pull request for armsp:feature into master in armsp/----

pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and feature, Head ref must be a branch

Attempt from the local feature branch:

(feature)$ gh pr create --title "Adding readme" --body "Testing pr from cli" --head armsp:feature

Creating pull request for armsp:feature into master in armsp/----

pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and feature, Head ref must be a branch

The general steps for the whole situation is -

  1. Commit and push some files from local main to remote main
  2. Make a new local branch feature, edit something, commit
  3. PR
    1. Use --head arguement of gh from local branch to make PR directly to remote without making the same remote branch
    2. Use --head arguement of gh from the local master without making a remote branch

I have seen a couple of issues on the github cli repo and they seem to have been fixed in a release, but it unfortunately still doesn't work for me.

  • Issue 1: https://github.com/cli/cli/issues/1820
  • Issue 2: https://github.com/cli/cli/issues/1709

My gh version

$ gh version
gh version 1.2.1 (2020-11-11)

NOTE: It is IMPERATIVE that I make the PR completely via terminal/cli.

like image 753
jar Avatar asked Nov 07 '22 04:11

jar


People also ask

Can you create a pull request without a branch?

To create a pull request, you need to have made your code changes on a separate branch or forked repository. From the open repository, select the Create button and select Pull request in the This repository section of the dropdown menu.

How do I pull pull request from GitHub?

Under your repository name, click Pull requests. In the list of pull requests, click the pull request you'd like to modify. To choose where you'd like to open the pull request, select the Open with drop-down and click one of the tabs.


1 Answers

You can't, you should at least create a branch on the remote first.

After the mandatory introduction on what is a Pull Request in Git vs GitHub, I'll quote the following:

Pull requests let you tell others about changes you've pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch. source.

GitHub PR expect some code on the remote GitHub server, at least a branch.

Create a pull request to propose and collaborate on changes to a repository. These changes are proposed in a branch, which ensures that the default branch only contains finished and approved work. source.

You expect to open a Pull Request on remote for a branch that doesn't exists. Create the branch first, then try again. Remember that you won't be able to have the remote automatically fetching or pulling content from your local to the remote, so in the end you'll have to push it.

like image 157
Daemon Painter Avatar answered Nov 15 '22 12:11

Daemon Painter