Integrating Stash Pull Requests into Your Git WorkflowApril 28, 2015
Here at MichiganLabs, we use Git for version control and Atlassian Stash as an interface to our Git repos for code review and discussion. As someone who prefers the CLI interface to Git, I keep looking for ways to ways to integrate Stash (which is primarily a web based tool) with the Git command line.
The primary feature I wanted was a quick and easy way to be able to create pull requests in Stash with a Git command.
First, install the Stash CLI tool:
$ gem install atlassian-stash<br /> $ stash configure<br />
When asked for a password, you can either enter your Stash password or leave it blank to be asked every time. I recommend not giving your password as it is stored as plaintext in
Once you have that installed and configured, you can begin making pull requests in Stash from the command line:
$ stash pull-request target-branch @reviewer1 @reviewer2 @reviewerN<br />
That’s great, but it’s a lot of stuff to type for each pull request. We usually involve our whole team in the pull requests for our projects, so the list of reviewers doesn’t change that often. It would be nice to be able to save a default list of reviewers and target branch somewhere. To do this, we can make a custom Git command that uses Git’s built-in settings storage system.
When you run a Git command, such as “
git foobar“, if the command is not built in to Git, the
$PATH will be searched for an executable called
git-foobar. Git then runs that executable and passes it any remaining arguments. Knowing this, we can create custom git commands simply by putting a new script in the
Save the following as
#!/bin/bash</p> <p>DEFAULT_BRANCH=$(git config stash.default-branch)<br /> DEFAULT_REVIEWERS=$(git config stash.default-reviewers)</p> <p>if [ "$#" -ne 0 ]; then<br /> stash pull-request $@<br /> else<br /> echo "stash pull-request $DEFAULT_BRANCH $DEFAULT_REVIEWERS"<br /> stash pull-request $DEFAULT_BRANCH $DEFAULT_REVIEWERS<br /> fi<br />
Make it executable and move it to somewhere in your
$PATH (such as
/usr/bin/ for example):
$ chmod +x git-pr<br /> $ sudo mv git-pr /usr/bin/<br />
You can set up a global default configuration (stored in
$ git config --global stash.default-branch develop<br /> $ git config --global stash.default-reviewers "@reviewer1 @reviewer2 @reviewerN"<br />
This can, of course, be overridden per repo by re-running the commands without the
--global flag (and the settings will be stored in
To create a pull request in Stash:
$ git pr<br />
If you don’t give any additional arguments, the defaults you set in your Git config will be used. You can see these defaults at any time with:
$ git config -l<br />
git-pr will accept the same arguments as the original
stash command line tool so you can do one-time overrides if you wish:
$ git pr master @reviewerM<br />
Thats it! Happy pull requesting!
Stay in the loop with our latest content!
Select the topics you’re interested to receive our new relevant content in your inbox. Don’t worry, we won’t spam you.
How to Build a Better App UI Architecture - Part 2November 19, 2019
Following up on the importance of consistency and reusability in Part 1, let's look at how to optimize the UI system for better consistency and reusability. We’ll begin by breaking down an iOS app, then look at how to build an interfaces-based system.Read more
2022 Best and Brightest Winners in West MichiganMay 2, 2022
The Best and Brightest Companies to Work For® competition identifies and honors organizations that display a commitment to excellence in operations and employee enrichment that lead to increased productivity and financial performance!Read more
Working From Home: Lessons Learned From A Forced ExperimentMarch 19, 2021
Prior to the pandemic, WFH seemed like a frightening notion for many. Organizations wondered if employees could actually be productive working remote? Well, it’s been a year since our forced experiment first began and what has it taught us? …That it was great!…until it wasn’t.Read more