Skip to content

caarlos0-graveyard/zsh-open-pr

Repository files navigation

open-pr Build Status

Open pull requests from command line.

gif showing open-pr in action

What it does

Basically, when you call git open-pr, the function will verify if you are working on a fork (by convention, you have an upstream remote), then, it will open your browser in the correct URL so you can just hit the Create Pull Request button.

The function also accepts one argument, in case you want to specify another target branch (instead of master, which is the convention).

URL breakdown:

https://github.com/target-remote/repo/compare/master...origin:random-feature
          |           |            |    |        |   |    |     |
          |           |            |    |        |   |    |      -> the branch
          |           |            |    |        |   |    |         you want
          |           |            |    |        |   |    |         to submit
          |           |            |    |        |   |    |
          |           |            |    |        |   |     -> will appear only
          |           |            |    |        |   |        if you are
          |           |            |    |        |   |        working in a fork
          |           |            |    |        |   |
          |           |            |    |        |    -> default GitHub compare
          |           |            |    |        |       thing
          |           |            |    |        |
          |           |            |    |         -> target branch
          |           |            |    |
          |           |            |     -> default GitHub endpoint to open a PR
          |           |            |
          |           |             -> the target repository, also from origin
          |           |                or upstream remotes
          |           |
          |            -> can be both origin or upstream
          |
           -> default host

Usage

For example, when you work on your own project:

$ git remote -v
origin  [email protected]:caarlos0/open-pr.git (fetch)
origin  [email protected]:caarlos0/open-pr.git (push)

$ git branch
* master

$ git checkout -b random-feature
$ touch this-file-is-important
$ git add -A
$ git commit -m 'did some stuff'
$ git push
$ git open-pr
# will browse https://github.com/caarlos0/open-pr/compare/master...random-feature

Working on a fork:

$ git remote -v
origin  [email protected]:random-user/open-pr.git (fetch)
origin  [email protected]:random-user/open-pr.git (push)
upstream  [email protected]:caarlos0/open-pr.git (fetch)
upstream  [email protected]:caarlos0/open-pr.git (push)

$ git branch
* master

$ git checkout -b random-feature
$ touch this-file-is-important
$ git add -A
$ git commit -m 'did some stuff'
$ git push
$ git open-pr
# will browse https://github.com/caarlos0/open-pr/compare/master...random-user:random-feature

Previous example, but to a develop branch, for instance:

$ git open-pr develop
# will browse https://github.com/caarlos0/open-pr/compare/develop...random-user:random-feature

Install using antibody

$ antibody bundle caarlos0/open-pr kind:path

Install using Fig

Fig adds apps, shortcuts, and autocomplete to your existing terminal.

Install zsh-open-pr in just one click.

Usage

Just hit git open-pr on your repositories.

You can also alias it:

$ git config --global alias.pr open-pr
$ git pr

But I like the following approach more:

gpr() {
  git push origin HEAD && git open-pr "$@"
}

So I can git push and git open-pr in a single, three letters command:

$ gpr

Contributing

The project is linted with Shellcheck and have unit tests. Please, take a look at them and execute ./build.sh to make sure it all works well. 🍻

About

Open pull requests from the command line.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages