DEV Community

Modasser Billah
Modasser Billah

Posted on

1 1

Shell Function for Pulling PRs

Fetching PRs opened by others for reviewing or testing new functionalities is a common task. Generally, you'd do the following for this:

git fetch upstream pull/<PR_NUMBER>/head:<BRANCH> && git checkout <BRANCH>

Typing this everytime can soon become irritating and you can't have an alias for it because PR number and branch name will vary.

So, shell function comes to the rescue! Functions can take parameters, so it makes our lives easier in this case.

So, if you want a shorthand for the above commands, try the following:

  • Put this in your shell configuration file like, .bashrc or .zshrc :
  • Source the config file with source ~/<Shell_Config_File_Name>

  • Fetch and checkout a PR branch with: pr <PR_NUMBER> <USER:BRANCH>

The shell function is a bit opinionated. I prefer to name branches as originally named by the author in their fork. This helps keep track when you have a lot of branches.

GitHub has recently introduced a copy button beside the branch name.

copy_button

So, it makes it easier just to click that button to copy the branch name but it comes with a user name as well. But you don't have to worry about it, just copy it as it is with the button and use that as the second variable to call the shell function. The first line of the function splits and takes only the branch name to use it as the new branch name.

Happy hacking!

Initially published at: http://modasserbillah.ml

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay